Results 1 to 14 of 14

Thread: How do I send data with http post request?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How do I send data with http post request?

    What is exactly that you don't understand? This is a single function call dependant of the source and destination of the data, so I'm not sure what kind of example would you like to see.

    Qt Code:
    1. QIODevice *outgoing = ...;
    2. QIODevice *incoming = ...;
    3. QHttp *http = ...;
    4. // this one
    5. connect(http, SIGNAL(done(bool)), ...);
    6. // or this one
    7. connect(incoming, SIGNAL(readyRead()), ...);
    8. // or something else...
    9. int id = http->post("/somepath", outgoing, incoming);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    Well, first of all, I want to send data to a php page so that the php page can read values from the POST variables $_POST['foo'] $_POST['bar'] (excuse me for the php code).

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How do I send data with http post request?

    And the problem is you don't know how to format the data, right? Sorry but this is out of scope of this forum. I suggest you take a network sniffer such as iptraf, ettercap or tcpdump, send a post request to some php page and see how the data is formatted.

  4. #4
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    Yes that's probably it. Thanks anyway.

  5. #5
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    Ah, I think I've solved it now.

    Qt Code:
    1. QByteArray* ba=new QByteArray("a=aaa&b=bbb&ok=ok");
    2. const QString s("/url.php Accept: text/html, text /plain, text/css, text/sgml, */* ;q=0.01\nAccept-Encoding : gzip, bzip2\nAccept-Language: en\nPragma: no-cache\nCache-Control: no-cache\nUser-Agent: Foobar\nReferer: http://localhost /a.php\nContent-type:application/x-www-form-urlencoded\nContent-lentgh::17\n");
    3. QHttpobject->post( s, *ba);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How do I send data with http post request?

    The headers should be in the data section, not the path section. The path should only contain "/url.php".

  7. #7
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    Well, I couldn't make it work if I put it in the data section. The parameters were not received in the webserver.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How do I send data with http post request?

    Did you remember about the extra newline after the last header?

  9. #9
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    I've added both \n and \n\n after ContentLength: 17 but no success.
    If anyone can re-write it properly, feel free to do so, because I can't make it work

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How do I send data with http post request?

    Take a network sniffer or netcat and see what the difference is.

  11. #11
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: How do I send data with http post request?

    Well the difference is big. The real webbrowser gives this extra information

    Qt Code:
    1. User-Agent: Links (2.2; Linux 2.6.25-gentoo-r7 x86_64; 150x41)
    2. Accept: */*
    3. Accept-Encoding: gzip, deflate, bzip2
    4. Accept-Charset: us-ascii, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, windows-1250, windows-1251, windows-1252, windows-1256, windows-1257, cp437, cp737, cp850, cp852, cp866, x-cp866-u, x-mac, x-mac-ce, x-kam-cs, koi8-r, koi8-u, koi8-ru, TCVN-5712, VISCII, utf-8
    5. Accept-Language: en, *;q=0.1
    6. Connection: Keep-Alive
    7. Content-Type: application/x-www-form-urlencoded
    To copy to clipboard, switch view to plain text mode 

    And I can not add any of these without adding them to the path.

Similar Threads

  1. Send Base64 encoded data
    By rmagro in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 17:58

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
  •  
Qt is a trademark of The Qt Company.