Results 1 to 7 of 7

Thread: problems in QHttp post method!

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy problems in QHttp post method!

    hi!
    I just want make a http login client ,
    but i got some problems.

    the server response a status-code 500 after the client request

    Qt Code:
    1. QHttp *http = new QHttp("login.xxxx.xxx.xx");
    2. QByteArray username("wbl9115");
    3. QByteArray password("19881010");
    4. QByteArray *data = new QByteArray("username="+username+"&password="+password+"&if_login=Y&B2=%B5%C7%C2%BC%28Login%29");
    5. http->request(buildHeader(),*data);
    To copy to clipboard, switch view to plain text mode 

    buildHeader()

    Qt Code:
    1. QHttpRequestHeader& buildHeader()
    2. {
    3. //constructe header
    4. header.addValue("Accept","image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument,"
    5. " application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/QVOD, */*");
    6. header.addValue("Referer","http://login.xxxx.xxx.xx/index.jsp");
    7. header.addValue("Accept-Language","zh-cn");
    8. header.addValue("ContentType" ,"application/x-www-form-urlencoded");
    9. header.addValue("Accept-Encoding","gzip, deflate");
    10. header.addValue("UserAgent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727;"
    11. " Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)");
    12.  
    13.  
    14. header.addValue("Host", "login.xxxx.xxx.xx");
    15. header.addValue("Connection", "Keep-Alive");
    16. header.addValue("Cache-Control", "no-cache");
    17.  
    18.  
    19. return header;
    20. }
    To copy to clipboard, switch view to plain text mode 


    any ideas?
    thax !!
    Last edited by wysota; 6th April 2009 at 14:59. Reason: reformatted to look better

  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: problems in QHttp post method!

    Ok, but what is the request method? Looks like you didn't set it. And are you sure you want to send all those useless headers with the request? I.e. I don't think you want the answer to be deflated
    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. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problems in QHttp post method!

    Quote Originally Posted by wysota View Post
    Ok, but what is the request method?
    it appears that he used post() method for request as mentioned in his post.

    the server response a status-code 500 after the client request
    status code 500 means something is wrong with the server, not with the client

  4. #4
    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: problems in QHttp post method!

    Quote Originally Posted by talk2amulya View Post
    it appears that he used post() method for request as mentioned in his post.
    No. He wanted to use post, but he forgot to set it in the request.



    status code 500 means something is wrong with the server, not with the client
    Not necessarily. A bad (malformed?) request can cause a 5xx error. It means the server encountered an error but it doesn't mean the error wasn't caused by the client.

    Look that in his request there is no path and no method set for the request. Or at least not in the snippet he pasted. We don't know what was in the header originally but for sure with each request there will be more garbage there as he is operating on a non-const reference to the same object.
    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.


  5. #5
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems in QHttp post method!

    Of course the header is defined
    Qt Code:
    1. QHttpRequestHeader header("POST","/login/login1.jsp");
    To copy to clipboard, switch view to plain text mode 
    I just did't give this code , sorry!
    the server is work fine and the login succeed using web browser!!

  6. #6
    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: problems in QHttp post method!

    Ok, first return a copy of the request not a reference to it. Second, print the created header to string, dump it to screen and compare to data actually sent by the browser. Then do the same with the request contents.
    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.


  7. #7
    Join Date
    Apr 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problems in QHttp post method!

    thank you!

Similar Threads

  1. QHTTP POST problem
    By oscar in forum Qt Programming
    Replies: 5
    Last Post: 10th October 2009, 19:58
  2. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41
  3. QHttp has problems with some url's
    By whoops.slo in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2006, 23:16

Tags for this Thread

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.