Results 1 to 3 of 3

Thread: No output in HTTP request .. Help Required

  1. #1
    Join Date
    Jun 2011
    Posts
    8
    Qt products
    Qt3
    Platforms
    MacOS X

    Default No output in HTTP request .. Help Required

    Hi,

    I am trying to make a HTTP request. But when I am trying to bytearray output is null.
    Qt Code:
    1. public class test {
    2. private int httpGetId;
    3. private boolean httpRequestAborted;
    4. private QHttp qHttp;
    5. public test(){
    6. String url = "http://miniorb.in";
    7.  
    8. QUrl qURL = new QUrl(url);
    9. System.out.println(qURL.encodedHost());
    10. QHttpRequestHeader header = new QHttpRequestHeader("GET", "/index.html");
    11. header.setValue("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)");
    12. header.setValue("Pragma", "no-cache");
    13. header.setValue("Host","miniorb.in" );
    14.  
    15. qHttp = new QHttp();
    16. qHttp.setHost("minirob.in");
    17. qHttp.request(header);
    18.  
    19. httpGetId = qHttp.get(qURL.path());
    20. qHttp.requestFinished.connect(this, "httpRequestFinished(int,boolean)");
    21. qHttp.responseHeaderReceived.connect(this,"readResponseHeader(QHttpResponseHeader)");
    22.  
    23. QByteArray xyz = qHttp.readAll();
    24. System.out.println("xyz : " + xyz.size());
    25. System.out.println("print 1: " + qHttp.request(header));
    26. String str = "Divanshu On work";
    27. System.out.println("inside the finsihed()" + str);
    28. }
    29. private void httpRequestFinished(int requestId, boolean error)
    30. {
    31. System.out.println("httpRequestFinished");
    32. if (requestId != httpGetId){
    33. System.out.println("Error");
    34. return;
    35. }
    36.  
    37. }
    38. private void readResponseHeader(QHttpResponseHeader responseHeader)
    39. {
    40. if (responseHeader.statusCode() != 200) {
    41. httpRequestAborted = true;
    42. qHttp.abort();
    43. }
    44. }
    45. public static void main(String args[]){
    46. test window = new test();
    47. }
    48. }
    To copy to clipboard, switch view to plain text mode 

    please help me .. where I am doing wrong.

    Thanks in Advance !!
    Last edited by divanshu; 28th June 2011 at 07:43.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: No output in HTTP request .. Help Required

    What I think you are doing wrong is assuming that the code waits for the request to be processed. It, doesn't and your test() function should end in .request() call.

    When the request has been processed, Qt calls your httpRequestFinished() callback function. That is where youd should check what you got.

    See: http://doc.qt.nokia.com/latest/qhttp.html#request

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: No output in HTTP request .. Help Required

    Also, QHttp is obsolete and provided for old code only. It should not be used for new code. Use QNetwork* instead.

Similar Threads

  1. How to make a HTTP request in QTJambi
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 28th June 2011, 06:29
  2. http request without signals and slots
    By whites11 in forum Newbie
    Replies: 6
    Last Post: 7th January 2010, 16:39
  3. HTTP request
    By Trok in forum Qt Programming
    Replies: 9
    Last Post: 5th January 2010, 14:49
  4. problem with Synchronous Http request
    By rchaitanya in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 30th January 2009, 11:03
  5. http request
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2008, 19: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
  •  
Qt is a trademark of The Qt Company.