Results 1 to 3 of 3

Thread: How to make a HTTP request in QTJambi

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

    Default How to make a HTTP request in QTJambi

    How I can make a HTTP request in QT jambi.

    Qt Code:
    1. QUrl qURL = new QUrl(url);
    2. System.out.println(qURL.encodedHost());
    3. QHttpRequestHeader header = new QHttpRequestHeader("GET", "/index.html");
    4.  
    5. header.setValue("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)");
    6. header.setValue("Pragma", "no-cache");
    7.  
    8. header.setValue("Host","miniorb.in" );
    9.  
    10. QObject qObject = new QObject();
    11.  
    12. QHttp qHttp = new QHttp();
    13. qHttp.setHost("minirob.in");
    14. //qHttp.currentRequest();
    15. qHttp.request(header);
    16.  
    17.  
    18.  
    19.  
    20.  
    21. QByteArray xyz = qHttp.readAll();
    To copy to clipboard, switch view to plain text mode 

    I tried to connect with the page in this way. but when I am trying to read it, it is giving me blank output. help me how i can fix it.


    Thanks In advance !!!

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: How to make a HTTP request in QTJambi

    You must connect void QHttp::requestFinished ( int id, bool error ) or QHttp::done ( bool error ) to some of your slots and then use readAll().

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

    Default Re: How to make a HTTP request in QTJambi

    can you explain me what is slot ... i read this thing from tutorial .. but i am not very clear how to connect with slot ..


    Added after 54 minutes:


    I tried to add slot in my code .. but it is still not working .. please point out my mistake in my code ...

    Qt Code:
    1. package com.trolltech.qt.webkit;
    2. import sun.awt.RequestFocusController;
    3. import sun.security.pkcs.ParsingException;
    4. import com.trolltech.qt.QtEnumerator;
    5. import com.trolltech.qt.QSignalEmitter.Signal1;
    6. import com.trolltech.qt.core.QByteArray;
    7. import com.trolltech.qt.core.QObject;
    8. import com.trolltech.qt.core.QUrl;
    9. import com.trolltech.qt.core.QUrl.ParsingMode;
    10. import com.trolltech.qt.gui.QApplication;
    11. import com.trolltech.qt.network.QHttp;
    12. import com.trolltech.qt.network.QHttpRequestHeader;
    13. import com.trolltech.qt.network.QHttpResponseHeader;
    14. import com.trolltech.qt.network.QNetworkAccessManager;
    15. import com.trolltech.qt.network.QNetworkReply;
    16. import com.trolltech.qt.network.QNetworkRequest;
    17.  
    18. public class test {
    19. private int httpGetId;
    20. private boolean httpRequestAborted;
    21. private QHttp qHttp;
    22. public test(){
    23. String url = "http://www.msn.com/st?=1";
    24.  
    25. QUrl qURL = new QUrl(url);
    26. System.out.println(qURL.encodedHost());
    27. QHttpRequestHeader header = new QHttpRequestHeader("GET", "/index.html");
    28. header.setValue("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)");
    29. header.setValue("Pragma", "no-cache");
    30. header.setValue("Host","miniorb.in" );
    31.  
    32. qHttp = new QHttp();
    33. qHttp.setHost("minirob.in");
    34. qHttp.request(header);
    35.  
    36. httpGetId = qHttp.get(qURL.path());
    37. qHttp.requestFinished.connect(this, "httpRequestFinished(int,boolean)");
    38. qHttp.responseHeaderReceived.connect(this,"readResponseHeader(QHttpResponseHeader)");
    39.  
    40. QByteArray xyz = qHttp.readAll();
    41. System.out.println("xyz : " + xyz.size());
    42. System.out.println("print 1: " + qHttp.request(header));
    43. String str = "Divanshu On work";
    44. System.out.println("inside the finsihed()" + str);
    45. }
    46. private void httpRequestFinished(int requestId, boolean error)
    47. {
    48. System.out.println("httpRequestFinished");
    49. if (requestId != httpGetId){
    50. System.out.println("Error");
    51. return;
    52. }
    53.  
    54. }
    55. private void readResponseHeader(QHttpResponseHeader responseHeader)
    56. {
    57. if (responseHeader.statusCode() != 200) {
    58. httpRequestAborted = true;
    59. qHttp.abort();
    60. }
    61. }
    62. public static void main(String args[]){
    63. test window = new test();
    64. }
    65. }
    To copy to clipboard, switch view to plain text mode 


    Thanks in advance !!!
    Last edited by divanshu; 28th June 2011 at 06:29.

Similar Threads

  1. http request without signals and slots
    By whites11 in forum Newbie
    Replies: 6
    Last Post: 7th January 2010, 16:39
  2. HTTP request
    By Trok in forum Qt Programming
    Replies: 9
    Last Post: 5th January 2010, 14:49
  3. problem with Synchronous Http request
    By rchaitanya in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 30th January 2009, 11:03
  4. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.