Results 1 to 3 of 3

Thread: Replacing QHttp.get() with QNetworkAccessManager

  1. #1
    Join Date
    Jun 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Replacing QHttp.get() with QNetworkAccessManager

    Hi,

    I've just installed QT 5.0 and realized that QHttp has been removed.
    I'm using it for downloading an XML-reply from Amazon Webservices.
    I tried to redesign my code.
    With a simple Adress "www.google.de" it's working.

    Here is a code snipped:
    Qt Code:
    1. ...
    2. m_netManager = new QNetworkAccessManager(this);
    3. QUrl url("http://webservices.amazon.de/onca/xml?AWSAccessKeyId=1HXFTRJCMBZPF4PGQ2G2&AssociateTag=wwwsealsoftde-20&IdType=EAN&ItemId=5051890049414&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes%2CRequest%2CEditorialReview&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-31T11%3A03%3A27Z&Signature=M6P6gs%2FXQ6pUnK8ZqZq9LThV7Tf%2FM5J6GYfI8Qdgt3Q%3D");
    4. m_netRequest.setUrl(url);
    5. m_netReplyData = m_netManager->get(m_netRequest);
    6. connect(m_netReplyData, SIGNAL(error(QNetworkReply::NetworkError)),
    7. this, SLOT(slotErrorData(QNetworkReply::NetworkError)));
    8. ...
    9.  
    10.  
    11. void HttpData::slotErrorData(QNetworkReply::NetworkError code){
    12. qDebug()<<"HttpData::slotErrorData";
    13. if(code == QNetworkReply::OperationCanceledError){
    14. ...
    15. }else{
    16. qDebug()<<"Errorstring: "<< m_netReplyData->errorString();
    17. qDebug()<<"Errorcode"<<code;
    To copy to clipboard, switch view to plain text mode 
    This is the Errorstring:
    http://webservices.amazon.de/onca/xm...GYfI8Qdgt3Q%3D - server replied: Bad Request

    If this ist not enough code I can write a small sample programm.

    Can someone help me with this Problem, with QHttp.get() this code was working?

    Greetings,

    Grisu

    Hi,

    I've just installed QT 5.0 and realized that QHttp has been removed.
    I'm using it for downloading an XML-reply from Amazon Webservices.
    I tried to redesign my code.
    With a simple Adress "www.google.de" it's working.

    Here is a code snipped:
    Qt Code:
    1. ...
    2. m_netManager = new QNetworkAccessManager(this);
    3. QUrl url("http://webservices.amazon.de/onca/xml?AWSAccessKeyId=1HXFTRJCMBZPF4PGQ2G2&AssociateTag=wwwsealsoftde-20&IdType=EAN&ItemId=5051890049414&Operation=ItemLookup&ResponseGroup=Images%2CItemAttributes%2CRequest%2CEditorialReview&SearchIndex=All&Service=AWSECommerceService&Timestamp=2012-12-31T11%3A03%3A27Z&Signature=M6P6gs%2FXQ6pUnK8ZqZq9LThV7Tf%2FM5J6GYfI8Qdgt3Q%3D");
    4. m_netRequest.setUrl(url);
    5. m_netReplyData = m_netManager->get(m_netRequest);
    6. connect(m_netReplyData, SIGNAL(error(QNetworkReply::NetworkError)),
    7. this, SLOT(slotErrorData(QNetworkReply::NetworkError)));
    8. ...
    9.  
    10.  
    11. void HttpData::slotErrorData(QNetworkReply::NetworkError code){
    12. qDebug()<<"HttpData::slotErrorData";
    13. if(code == QNetworkReply::OperationCanceledError){
    14. ...
    15. }else{
    16. qDebug()<<"Errorstring: "<< m_netReplyData->errorString();
    17. qDebug()<<"Errorcode"<<code;
    To copy to clipboard, switch view to plain text mode 
    This is the Errorstring:
    http://webservices.amazon.de/onca/xm...GYfI8Qdgt3Q%3D - server replied: Bad Request

    If this ist not enough code I can write a small sample programm.

    Can someone help me with this Problem, with QHttp.get() this code was working?

    Greetings,

    Grisu

    Always the same....
    Im working on this for two days. And 30 minutes after this post I got it :-)
    Qt Code:
    1. m_netRequest.setUrl(QUrl("http://"+strUrl.host()+strUrl.path()));
    2. m_netReplyData = m_netManager->post(m_netRequest,strUrl.encodedQuery());
    To copy to clipboard, switch view to plain text mode 
    Last edited by Grisu; 31st December 2012 at 11:59.

  2. #2
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Replacing QHttp.get() with QNetworkAccessManager

    I have the same problem and I am kind of stuck.

    My situation is also using with QNetworkAccessManager using amazon S3 Url. The QNetworkReply::errorString() coming back is:

    Error downloading http://mybucket.s3.amazonaws.com/app...htMSQopo4%253D - server replied: Forbidden


    BUT- the URL that is set on QNetworkReply and QNetworkRequest is different:

    http://mybucket.s3.amazonaws.com/app...kYhtMSQopo4%3D


    Notice the %253D at the end of the URL in the QNetworkReply::errorString()

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Replacing QHttp.get() with QNetworkAccessManager

    The QUrl() constructor you are both using:
    QUrl::QUrl ( const QString & url )

    Constructs a URL by parsing url. url is assumed to be in human readable representation, with no percent encoding. QUrl will automatically percent encode all characters that are not allowed in a URL.
    You are both passing encoded strings, which then get encoded a second time.

    The docs also tell you how to remedy this with QUrl::fromEncoded(), or you could not encode it in the first place, or build it from components using QUrl methods.

  4. The following user says thank you to ChrisW67 for this useful post:

    jsuppe (1st February 2013)

Similar Threads

  1. QNetworkAccessManager or QHttp help required
    By prasad.borkar in forum Newbie
    Replies: 3
    Last Post: 20th April 2011, 07:30
  2. QNetworkAccessManager and QHttp doesn't sends anything
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2010, 22:20
  3. QNetworkAccessManager or QHttp
    By mind_freak in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 20:24
  4. QNetworkAccessManager vs QHttp
    By jiveaxe in forum Newbie
    Replies: 3
    Last Post: 17th February 2009, 14:07
  5. Replies: 11
    Last Post: 20th January 2009, 14:10

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.