Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sending HTTP POST network request?
QtWS25 Last Chance

Sending HTTP POST network request?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ashley
    wrote on last edited by Ashley
    #1

    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. :)

    1 Reply Last reply
    1
    • A Offline
      A Offline
      Ashley
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved