Sending HTTP POST network request?

  • 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();
    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. :)

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.