Results 1 to 4 of 4

Thread: QHttp - how should I connect?

  1. #1
    Join Date
    Jun 2009
    Location
    Kraków, Poland
    Posts
    23
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QHttp - how should I connect?

    Hello,
    I have a web page with (only) script which uses POST data. I want to write a program which would simply visit that page (without showing it / downloading / whatever) after clicking a button - so I wrote a function, which is called while clicking button:
    Qt Code:
    1. QByteArray content("?id=1&etc=SomePostData");
    2. QHttpRequestHeader header("POST", "/file.php");
    3. header.setValue("Host", "www.hostname.com");
    4. header.setContentType("application/x-www-form-urlencoded");
    5. header.setContentLength(content.length());
    6.  
    7. QHttp *http = new QHttp("www.hostname.com", 80);
    8. http->request(header, content);
    To copy to clipboard, switch view to plain text mode 

    and it actually does nothing :/
    Would you tell me, what I've done wrong?
    If i try to save that page into a file with request(header, content, &file) I got some error - program shuts down with window like uncatched exception one...

    Thainks in an advance,
    Fenix Voltres

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

    Default Re: QHttp - how should I connect?

    I think you're using GET instead of POST in your data formatting, so use the GET method in the request as well. Anyway I'd suggest to use QNetworkAccessManager - it is much easier to use.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Fenix Voltres (25th June 2009)

  4. #3
    Join Date
    Jun 2008
    Location
    Germany/Belarus/Sweden
    Posts
    53
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp - how should I connect?

    connect to
    Qt Code:
    1. void stateChanged ( int state )
    To copy to clipboard, switch view to plain text mode 
    signal to debug what http do.
    read data on
    Qt Code:
    1. void QHttp::readyRead ( const QHttpResponseHeader & resp )
    To copy to clipboard, switch view to plain text mode 
    signal.

    and try to set host.

    Qt Code:
    1. http->setHost("www.hostname.com");
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jun 2009
    Location
    Kraków, Poland
    Posts
    23
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QHttp - how should I connect?

    Quote Originally Posted by wysota View Post
    I think you're using GET instead of POST in your data formatting, so use the GET method in the request as well. Anyway I'd suggest to use QNetworkAccessManager - it is much easier to use.
    Of course - my mistake - this is GET. Anyway - this method doesn't work for me in this way...
    But QNetworkAccessManager works perfectly well! Thanks much!

Similar Threads

  1. Connect Problem
    By nrabara in forum Newbie
    Replies: 3
    Last Post: 4th May 2009, 12:19
  2. Application only 'animates' once
    By arkain in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2009, 08:09
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41
  5. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19

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.