Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: QNetworkAccessManager and redirections

  1. #1
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QNetworkAccessManager and redirections

    I have problems handling redirects using QNetworkAccessManager. Could I get some help? Example code here: http://pastebin.com/bu7rWx2X

    I can't get the file that I want (hosted on sourceforge) using the first link in the code, but if I use the second link (commented), I get the file without problems.

    I know that this is almost only-c++-code forum, but the code is ~50 lines and I haven't used python-specific things. Only Qt calls.

    Thanks

  2. #2
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    Not a single reply? Nobody knows something about QNAM and redirections?

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QNetworkAccessManager and redirections

    I looked briefly on Your code, so maybe I'm wrong on this - also tired from all day work ;/, but why do You use https for sourceforge?, try http.
    Also try to use WireShark and capture Your request and browser request and compare both. That's probably fastest way to figure out why this don't work.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

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

    alexandernst (22nd September 2010)

  5. #4
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    I use https because that's the link. Qt should be able to manage that link. Also, going the Wireshark way is way too wrong for that problem. That is clearly a Qt bug.
    Both wget and curl are perfectly able to handle that link, so Qt should be able to handle it too. Could somebody try to run the code or maybe even better, point me to the right direction.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    Maybe you need to handle the redirection yourself. I'm not sure QNetworkAccessManager does that on its own. There are situations when you'd like to know a redirection is in place and not actually follow it blindly so I guess it could be that QNetworkAccessManager will not make the second request automatically.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  8. #6
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    wysota, I already handle the redirections. I'm here because I'm doing something wrong and I need and example/advice.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    So what happens exactly if you use the first link? Did you connect appropriate signals and slots regarding handling ssl errors as it says in the docs?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  11. #8
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    Yes, I connected the appropriate signals. I also manage sslErrors signal, but no ssl errors happen at all.
    In my app I get a 302 with the same URL but http instead of https. Then I get a 200 with exactly the same URL as from the 302 redirection. And it stops there.

    Using wget I get 302, 302, 302 and then 200. I also saw a cookie, but I don't know how to implement/use them with my code. I haven't found any example about doing that.

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    Quote Originally Posted by alexandernst View Post
    Then I get a 200 with exactly the same URL as from the 302 redirection. And it stops there.
    And what would you expect? 200 is the last status code in chain, there are no more requests after that. Did you look at the headers you get with the response?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  14. #10
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    I'm not sure if I'm looking them the right way. I use this:

    for item in reply.rawHeaderList():
    print "HEADER: " + reply.rawHeader(str(item))

  15. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    And what do you get?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  17. #12
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    This is what I get using my app:

    Qt Code:
    1. UPDATE: 163 of 163
    2. ERROR CODE: (302, True)
    3. HEADER: nginx/0.7.63
    4. HEADER: Mon, 20 Sep 2010 20:00:07 GMT
    5. HEADER: text/html; charset=UTF-8
    6. HEADER: close
    7. HEADER: sf.consume=fc962df5a9f7681b705057aa739f02d9b40bdab2gAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUDX2lkcQVVIGViNjkxNjc2YTNhZGNjYjhkNWE3ZGYyODQwM2EwZjQwcQZVDl9hY2Nlc3NlZF90aW1lcQdHQdMl71HYCOFVDl9jcmVhdGlvbl90aW1lcQhHQdMl71HYCN11Lg==; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/
    8. HEADER: http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download
    9. HEADER: 163
    10. REDIRECT: PyQt4.QtCore.QUrl(u'http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download')
    11. UPDATE: 697 of 17593
    12. UPDATE: 2145 of 17593
    13. UPDATE: 3593 of 17593
    14. UPDATE: 5041 of 17593
    15. UPDATE: 6489 of 17593
    16. UPDATE: 7937 of 17593
    17. UPDATE: 9385 of 17593
    18. UPDATE: 10833 of 17593
    19. UPDATE: 12281 of 17593
    20. UPDATE: 13729 of 17593
    21. UPDATE: 15177 of 17593
    22. UPDATE: 16625 of 17593
    23. UPDATE: 17593 of 17593
    24. ERROR CODE: (200, True)
    25. HEADER: nginx/0.7.63
    26. HEADER: Mon, 20 Sep 2010 20:00:08 GMT
    27. HEADER: text/html; charset=utf-8
    28. HEADER: close
    29. HEADER: no-cache
    30. HEADER: no-cache
    31. HEADER: VISITOR=4c97bd47d3179d696c000c1b; expires="Thu, 17-Sep-2020 20:00:08 GMT"; httponly; Max-Age=315360000; Path=/
    32. sf.consume=18a7bbdc908cf4ebec1332d6b6582817c21d4817gAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUFcHJlZnNxBX1xBlUOdXNlc19yZWxhdGlvbnNxB4lVB3ZlcnNpb25xCFUBMlUDa2V5cQlVGDRjOTdiZDQ3ZDMxNzlkNjk2YzAwMGMxYnEKVQNfaWRxC1UgYjhjNzIwZTg0YTIwMTEyYTllMWNlODE0NjIxNjU0NTVxDFUOX2FjY2Vzc2VkX3RpbWVxDUdB0yXvUiUFHVUOX2NyZWF0aW9uX3RpbWVxDkdB0yXvUiUD/3Uu; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/
    33. HEADER: 17593
    To copy to clipboard, switch view to plain text mode 

    and it hangs there.

    And this is what I get with wget:

    Qt Code:
    1. --2010-09-20 22:11:01-- https://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download
    2. Resolviendo sourceforge.net... 216.34.181.60
    3. Connecting to sourceforge.net|216.34.181.60|:443... conectado.
    4. Petición HTTP enviada, esperando respuesta... 302 Found
    5. Localización: http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download [siguiendo]
    6. --2010-09-20 22:11:02-- http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download
    7. Connecting to sourceforge.net|216.34.181.60|:80... conectado.
    8. Petición HTTP enviada, esperando respuesta... 302 Found
    9. Localización: http://downloads.sourceforge.net/project/python-jake/betas/Jake-PyQT4-0.1.zip?r=&ts=1285012816&use_mirror=garr [siguiendo]
    10. --2010-09-20 22:11:02-- http://downloads.sourceforge.net/project/python-jake/betas/Jake-PyQT4-0.1.zip?r=&ts=1285012816&use_mirror=garr
    11. Resolviendo downloads.sourceforge.net... 216.34.181.59
    12. Connecting to downloads.sourceforge.net|216.34.181.59|:80... conectado.
    13. Petición HTTP enviada, esperando respuesta... 302 Found
    14. Localización: http://garr.dl.sourceforge.net/project/python-jake/betas/Jake-PyQT4-0.1.zip [siguiendo]
    15. --2010-09-20 22:11:03-- http://garr.dl.sourceforge.net/project/python-jake/betas/Jake-PyQT4-0.1.zip
    16. Resolviendo garr.dl.sourceforge.net... 193.206.140.34, 2001:760:ffff:b0::34
    17. Connecting to garr.dl.sourceforge.net|193.206.140.34|:80... conectado.
    18. Petición HTTP enviada, esperando respuesta... 200 OK
    19. Longitud: 1218027 (1,2M) [application/zip]
    20. Saving to: `Jake-PyQT4-0.1.zip'
    21.  
    22. 100%[===================================================================================================================================================================================================>] 1.218.027 547K/s in 2,2s
    23.  
    24. 2010-09-20 22:11:05 (547 KB/s) - `Jake-PyQT4-0.1.zip' saved [1218027/1218027]
    To copy to clipboard, switch view to plain text mode 

  18. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    You are only showing header values and not keys (I think I can guess them correctly though). One thing I would surely do is to return the cookie set by the first request with the second request.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  20. #14
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    Yup, exactly! That's the thing that I don't know how to do. How do I return the cookie?
    Also, how do I show to header values + keys?

  21. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    Quote Originally Posted by alexandernst View Post
    Yup, exactly! That's the thing that I don't know how to do. How do I return the cookie?
    Setting a cookie jar for your QNAM should be enough. If not then you'll have to set the "Cookie" header in the second request.

    Also, how do I show to header values + keys?
    QNetworkReply::rawHeaderList() probably returns a list of header names (or "key: value" pairs).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  22. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  23. #16
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    Ok, now I'm setting a cookieJar this way:

    Qt Code:
    1. self.manager = QNetworkAccessManager()
    2. self.jar = QNetworkCookieJar()
    3. self.manager.setCookieJar(self.jar)
    To copy to clipboard, switch view to plain text mode 

    but I keep getting the same output.
    I also managed to show the keys&values if you wish to see the output:

    Qt Code:
    1. UPDATE: 163 of 163
    2. ERROR CODE: (302, True)
    3. HEADER: Server === nginx/0.7.63
    4. HEADER: Date === Tue, 21 Sep 2010 06:11:40 GMT
    5. HEADER: Content-Type === text/html; charset=UTF-8
    6. HEADER: Connection === close
    7. HEADER: Set-cookie === sf.consume=dbbb479a1e149425adaf118787d664ea2a761e9dgAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUDX2lkcQVVIDk1YWNiNmQxYzQzNjBkNjk0NjRmNzVkNThmM2Y5NzNmcQZVDl9hY2Nlc3NlZF90aW1lcQdHQdMmEycBVPhVDl9jcmVhdGlvbl90aW1lcQhHQdMmEycBVPN1Lg==; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/
    8. HEADER: Location === http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download
    9. HEADER: Content-Length === 163
    10. REDIRECT: PyQt4.QtCore.QUrl(u'http://sourceforge.net/projects/python-jake/files/betas/Jake-PyQT4-0.1.zip/download')
    11. UPDATE: 697 of 17537
    12. UPDATE: 2145 of 17537
    13. UPDATE: 3593 of 17537
    14. UPDATE: 5041 of 17537
    15. UPDATE: 6489 of 17537
    16. UPDATE: 7937 of 17537
    17. UPDATE: 9385 of 17537
    18. UPDATE: 10833 of 17537
    19. UPDATE: 12281 of 17537
    20. UPDATE: 13729 of 17537
    21. UPDATE: 15177 of 17537
    22. UPDATE: 17537 of 17537
    23. ERROR CODE: (200, True)
    24. HEADER: Server === nginx/0.7.63
    25. HEADER: Date === Tue, 21 Sep 2010 06:11:40 GMT
    26. HEADER: Content-Type === text/html; charset=utf-8
    27. HEADER: Connection === close
    28. HEADER: Pragma === no-cache
    29. HEADER: Cache-Control === no-cache
    30. HEADER: Set-cookie === VISITOR=4c984c9c91aa911ff50011b7; expires="Fri, 18-Sep-2020 06:11:40 GMT"; httponly; Max-Age=315360000; Path=/
    31. sf.consume=74bd0beb5266058fee435c8078db828cf65ffcaagAJ9cQEoVQhfZXhwaXJlc3ECY2RhdGV0aW1lCmRhdGV0aW1lCnEDVQoH9gETAw4HAAAAhVJxBFUFcHJlZnNxBX1xBlUOdXNlc19yZWxhdGlvbnNxB4lVB3ZlcnNpb25xCFUBMlUDa2V5cQlVGDRjOTg0YzljOTFhYTkxMWZmNTAwMTFiN3EKVQNfaWRxC1UgZWRmNmM5MzZmMjczZjFlNmI1ZTdkZjE1ZDk4ZTIyZjlxDFUOX2FjY2Vzc2VkX3RpbWVxDUdB0yYTJxjnklUOX2NyZWF0aW9uX3RpbWVxDkdB0yYTJxjmuHUu; expires=Tue, 19-Jan-2038 03:14:07 GMT; Path=/
    32. HEADER: Content-Length === 17537
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

  24. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    Check if the cookie is sent back with the second request. Also, what is the content of the second reply?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  25. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  26. #18
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    How can I check if the cookie was sent back?

    I think you can see the content of the second reply in my last post. Or you mean another thing?

  27. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager and redirections

    Quote Originally Posted by alexandernst View Post
    How can I check if the cookie was sent back?
    Either dump headers of the second request or run some network sniffer to check what goes through the network. You may use this one: NetworqDebugger.

    I think you can see the content of the second reply in my last post. Or you mean another thing?
    The content of the second reply is 17537 bytes long and you did not show it to us.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  28. The following user says thank you to wysota for this useful post:

    alexandernst (22nd September 2010)

  29. #20
    Join Date
    Jul 2009
    Location
    Valladolid, Spain
    Posts
    125
    Thanks
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QNetworkAccessManager and redirections

    That's because the app dies there. It just gets to the redirect and waits for something...
    I'll try wireshark when I'm at home.

Similar Threads

  1. QNetworkAccessManager within QThread
    By Tomdarkness in forum Newbie
    Replies: 17
    Last Post: 26th August 2014, 15:12
  2. qnetworkaccessmanager problem!
    By novamaster in forum Qt Programming
    Replies: 6
    Last Post: 7th August 2010, 11:46
  3. QNetworkAccessManager question
    By _Stefan in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2010, 12:21
  4. QNetworkAccessManager or QHttp
    By mind_freak in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 20:24
  5. How to Login using QNetworkAccessManager?
    By cydside in forum Newbie
    Replies: 1
    Last Post: 31st August 2009, 21:41

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.