Results 1 to 4 of 4

Thread: Sending HTTP POST network request

  1. #1

    Default 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:
    Qt Code:
    1. qUrl = new QUrl();
    2. qUrl->setHost(ipAddress);
    3. qUrl->setPort(port);
    4. qUrl->setPath("/login");
    5.  
    6. request = QNetworkRequest(qUrl)
    7. request.setRawHeader("Content-Length", QString::number(securityKey.size()).toLocal8Bit);
    8. ... more headers ...
    9.  
    10. QString content = "contents..."
    11.  
    12. QNetworkAccessManager* networkManager = new QNetworkAccessManager();
    13. networkManager->connectToHost(ipAddress, port);
    14.  
    15. networkManager->post(request, content.toLocal8Bit());
    To copy to clipboard, switch view to plain text mode 
    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 so I'm not sure if what I'm doing is correct.

    Any help would be much appreciated!
    Last edited by Ashley; 1st April 2015 at 15:57.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Sending HTTP POST network request

    Is your actual code maybe also missing the setting of the scheme for the URL?

    Cheers,
    _

  3. #3

    Default Re: Sending HTTP POST network request

    hi, something is happening now - I will investigate to see if it's a positive thing or not, will get back in a moment, thanks for the fast reponse

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sending HTTP POST network request

    You are not setting the Content-Type to" text/xml", maybe causing the server to discard the request.
    You are setting Content-length to the length of one thing and putting a different thing in the content. You do not need to explicitly set the content length anyway (IIRC).

Similar Threads

  1. QT5 http post request
    By marty.marty in forum Qt Programming
    Replies: 0
    Last Post: 14th January 2015, 12:44
  2. QT Http Post Request Problem
    By zzzuui in forum General Programming
    Replies: 0
    Last Post: 30th December 2012, 14:16
  3. How can I create HTTP post request with qt
    By vinayaka in forum Newbie
    Replies: 1
    Last Post: 10th December 2011, 10:00
  4. HTTP request POST in QT application
    By abdul_moiz in forum Newbie
    Replies: 5
    Last Post: 24th June 2011, 04:48
  5. How do I send data with http post request?
    By Morea in forum Qt Programming
    Replies: 13
    Last Post: 21st January 2009, 23:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.