Results 1 to 7 of 7

Thread: HTTPS request returns damaged HTML body

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: HTTPS request returns damaged HTML body

    Also might make sense to check out QNetworkAccessManager to handle all the HTTP level (and below) protocol for you.

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    ljuhrich (1st June 2013)

  3. #2
    Join Date
    Nov 2012
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Thumbs up Re: HTTPS request returns damaged HTML body

    NICE! It works!

    Thank you very much!

    both tips were very useful:

    1. After I changed Accpt–encoding to none, I got some readable text, but not everything.
    2. But when I changed the code using a QNetworkAcessmanager, it returned everything, and the code is a lot simpler.

    Qt Code:
    1. void MainWindow::doRequest()
    2. {
    3. // INITIALIZATION
    4.  
    5. // Read username, access token
    6. QString id = QString(ui->edUserID->text());
    7. QString access_token = QString(ui->edAcessToken->text());
    8.  
    9.  
    10. manager = new QNetworkAccessManager(this);
    11. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(resp(QNetworkReply*)));
    12.  
    13. QNetworkRequest request(
    14. "https://graph.facebook.com/"
    15. + id
    16. + "?fields=id,name,about,sports,likes,interests&method=GET&format=json&access_token="
    17. + QUrl::toPercentEncoding( access_token )
    18. );
    19. request.setRawHeader("Accept-Encoding", "none");
    20. request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0");
    21.  
    22. manager->get(request);
    23. }
    24.  
    25. void MainWindow::resp(QNetworkReply *reply)
    26. {
    27. QString responseData = QString::fromAscii(reply->readAll());
    28. ui->edResponse->setText( ui->edResponse->toPlainText() + "\r\n" + responseData);
    29. }
    To copy to clipboard, switch view to plain text mode 

    I wish you a nice day

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: HTTPS request returns damaged HTML body

    Just in case: one thing people who are new to using QNetworkAccessManager can miss is that it can be used for as many requests in parallel as one would want.
    I.e. in your code you create the object every time doRequest() is called, but you would only have to do it once.

    Each request is paired with a reply object and QNAM is able to process them individually, even multiple requests at the same time.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    ljuhrich (1st June 2013)

  6. #4
    Join Date
    Nov 2012
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6

    Default Re: HTTPS request returns damaged HTML body

    Thnk you for these nice tips, I always try to improve my skills — so every little tip helps me a lot and saves me from hours of debugging

  7. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: HTTPS request returns damaged HTML body

    Well, then I have another one

    You will need to delete the reply object, otherwise you are leaking it.
    One way to do that is to schedule its deletion in the slot connected to the finished signals

    Qt Code:
    1. void MainWindow::resp(QNetworkReply *reply)
    2. {
    3. QString responseData = QString::fromAscii(reply->readAll());
    4. ui->edResponse->setText( ui->edResponse->toPlainText() + "\r\n" + responseData);
    5.  
    6. reply->deleteLater(); // schedule deletion when event loop continues event processing
    7. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    ljuhrich (5th June 2013)

Similar Threads

  1. Replies: 1
    Last Post: 5th December 2012, 10:19
  2. Replies: 0
    Last Post: 22nd October 2012, 13:39
  3. Replies: 0
    Last Post: 3rd May 2011, 10:15
  4. any body using qextserialport?
    By yagabey in forum Newbie
    Replies: 4
    Last Post: 25th December 2007, 23:08
  5. Https POST Request
    By munna in forum Qt Programming
    Replies: 10
    Last Post: 11th November 2006, 15:24

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
  •  
Qt is a trademark of The Qt Company.