Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sending HTTP POST network request?
Ashley last edited by Ashley
I'm trying to send a HTTP POST login request in the following format:
POST /login HTTP/1.1 Content-Type: text/xml Content-Length: 450 Host: 123.456.78.91:80 KeepAlive-Interval: 5 [CONTENT (contains security key)]
Currently, my code is structured like:
qUrl = new QUrl(); qUrl->setHost(ipAddress); qUrl->setPort(port); qUrl->setPath("/login"); request = QNetworkRequest(qUrl) request.setRawHeader("Content-Length", QString::number(securityKey.size()).toLocal8Bit); ... more headers ... QString content = "contents..." QNetworkAccessManager* networkManager = new QNetworkAccessManager(); networkManager->connectToHost(ipAddress, port); networkManager->post(request, content.toLocal8Bit());
Currently I'm not receiving any response from the server so something's wrong. I'm wondering if anyone is able to identify what it may be? I haven't seen any examples online of people connecting to ip addresses/ports with Qt networking, only the URL addresses, so I'm not sure if what I'm doing is correct.
Any help would be much appreciated. :)
Ashley last edited by
I have just found I forgot to set the scheme, i.e. qUrl->setScheme("http");
Just testing if everything else is okay, assume the problem is solved for now, will edit replies/post if any further help needed.