Results 1 to 2 of 2

Thread: Http request doesn't respond when the host is local

  1. #1
    Join Date
    Jan 2011
    Location
    Nagercoil,Tamilnadu,India
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Http request doesn't respond when the host is local

    Hi, I am working with sync http request. The code what i get for that working correct on remote host(example:http://www.capeconsultancy.com). But it doesn't working on local host's(example:localhost). what was the problem? please help me!

    main.cpp

    Qt Code:
    1. #include "synchttp.h"
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. SyncHTTP h("http://www.capeconsultancy.com");//this working good but not localhost
    7. ///prepare output buffer
    8. QBuffer getOutput;
    9. h.syncGet("/",&getOutput );
    10. qDebug()<<getOutput.data();
    11. a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    synchttp.h

    Qt Code:
    1. #ifndef SYNCHTTP_H
    2. #define SYNCHTTP_H
    3.  
    4. #include <QHttp>
    5. #include <QEventLoop>
    6. #include <QBuffer>
    7.  
    8.  
    9. class SyncHTTP: public QHttp
    10. {
    11. Q_OBJECT
    12. public:
    13. /// structors
    14. SyncHTTP( QObject * parent = 0 )
    15. :QHttp(parent),requestID(-1),status(false){}
    16.  
    17. SyncHTTP( const QString & hostName, quint16 port = 80, QObject * parent = 0 )
    18. :QHttp(hostName,port,parent),requestID(-1),status(false){}
    19.  
    20. virtual ~SyncHTTP(){}
    21.  
    22. /// send GET request and wait until finished
    23. bool syncGet ( const QString & path, QIODevice * to = 0 )
    24. {
    25. ///connect the requestFinished signal to our finished slot
    26. connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));
    27. /// start the request and store the requestID
    28. requestID = get(path,to);
    29. /// block until the request is finished
    30. loop.exec();
    31. /// return the request status
    32. return status;
    33. }
    34.  
    35. /// send POST request and wait until finished
    36. bool syncPost ( const QString & path, QIODevice * data, QIODevice * to = 0 )
    37. {
    38. ///connect the requestFinished signal to our finished slot
    39. connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));
    40. /// start the request and store the requestID
    41. requestID = post(path, data , to );
    42. /// block until the request is finished
    43. loop.exec();
    44. /// return the request status
    45. return status;
    46. }
    47.  
    48. bool syncPost ( const QString & path, const QByteArray& data, QIODevice * to = 0 )
    49. {
    50. /// create io device from QByteArray
    51. QBuffer buffer;
    52. buffer.setData(data);
    53. return syncPost(path,&buffer,to);
    54. }
    55.  
    56. protected slots:
    57. virtual void finished(int idx, bool err)
    58. {
    59. /// check to see if it's the request we made
    60. if(idx!=requestID)
    61. return;
    62. /// set status of the request
    63. status = !err;
    64. /// end the loop
    65. loop.exit();
    66. }
    67.  
    68. private:
    69. /// id of current request
    70. int requestID;
    71. /// error status of current request
    72. bool status;
    73. /// event loop used to block until request finished
    74. QEventLoop loop;
    75. };
    76.  
    77. #endif
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance
    M Dineshkumar,
    Project Trainee,
    Cape Consultancy Services
    (http://www.capeconsultancy.com)
    India.

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

    Default Re: Http request doesn't respond when the host is local

    Show the code that doesn't work, rather than the code that does.

Similar Threads

  1. QGraphicsScene doesn't respond to mousePressEvent
    By Affenbrotbaum in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2010, 19:56
  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

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.