Results 1 to 12 of 12

Thread: how to make QHttp work with this URL

  1. #1
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default how to make QHttp work with this URL

    The HTTP example fails at this URL:
    http://downloads.sourceforge.net/isisimages/source.zip
    How to make it work?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    The link is being redirected to here :
    http://sourceforge.net/project/downl...se_mirror=kent

    On sourceforge I think you're always being redirected to a random mirror.

    Maybe you could find out somehow to which mirror you're being redirected.

    regards

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    Quote Originally Posted by ber_44 View Post
    The HTTP example fails at this URL:
    http://downloads.sourceforge.net/isisimages/source.zip
    How to make it work?
    Read the header location.... from first url and grab the next url ....

    on your case

    QString QHttpHeader::value ("Location")
    return the new url or path...

    sample read ....

    depend on ip client ... grab the next url mirror....


    Qt Code:
    1. void RegisterCookie(const QHttpResponseHeader &responseHeader )
    2. {
    3. ActualCook.clear();
    4. QStringList cookielist = responseHeader.allValues("set-cookie");
    5. for (int i = 0; i < cookielist.size(); ++i) {
    6. QString cokeline = cookielist.at(i);
    7. QStringList onlines = cokeline.split("=");
    8. QString cookiename = onlines.at(0);
    9. QString cookievalue = onlines.at(1);
    10. ActualCook.insert(i,QStringList() << cookiename << Url_Decode(cookievalue) << actualurl);
    11. /////////////////qDebug() << "### entry set-cookie pos=" << i << " name= " << cookiename << " value=" << Url_Decode(cookievalue);
    12. }
    13. //////////emit WatReturn(QString("One code=%1 - Other say = %2 \n%3").arg( responseHeader.statusCode() ).arg( responseHeader.reasonPhrase() ).arg(CookieVars()) );
    14. }
    To copy to clipboard, switch view to plain text mode 


    discovery on http://livehttpheaders.mozdev.org/

    Qt Code:
    1. http://downloads.sourceforge.net/isisimages/source.zip
    2.  
    3. GET /isisimages/source.zip HTTP/1.1
    4. Host: downloads.sourceforge.net
    5. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
    6. Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    7. Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
    8. Accept-Encoding: gzip,deflate
    9. Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    10. Keep-Alive: 300
    11. Connection: keep-alive
    12. Referer: http://www.qtcentre.org/forum//forum/newreply.php?do=postreply&t=6595
    13. Cookie: ebNewBandWidth_.sourceforge.net=589%3A1175362503265; __utmz=191645736.1176795478.834.46.utmccn=(referral)|utmcsr=qtcentre.org|utmcct=/forum/f-qt-programming-2/t-how-to-make-qhttp-work-with-this-url-6595.html|utmcmd=referral; username=gasSKXJewRo%3D; __utma=191645736.346796218.1169658266.1176747181.1176795478.834; sso_session_ser=yKK3e8LVW6r8auGwiHUNePItpalud5j%2B54olwzSzS4soMkSBvWa4R%2BJEPm6Wn30sQiHC17XThHPg3KMsC2qEPizzVh%2FYdN2K0Ec75%2FtfH%2B8mVoAtmF0bDYklJOqyuyLa%2B4%2BQqU5aYeW2GfRW%2FqCBbnKjYuiyNGIdc0g5ydI5sBQ%3D-5ead3f2617584e562295ee6a3be43f78; __utmc=191645736; __utmb=191645736
    14.  
    15. HTTP/1.x 301 Moved Permanently
    16. X-Powered-By: PHP/5.2.1
    17. Location: http://sourceforge.net/project/downloading.php?groupname=isisimages&filename=source.zip&use_mirror=heanet
    18. Content-Type: text/html
    19. Content-Length: 0
    20. Date: Tue, 17 Apr 2007 07:54:32 GMT
    21. Server: lighttpd/1.4.15
    22. ----------------------------------------------------------
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: how to make QHttp work with this URL

    Why are you complicating things so much? This should work:

    Qt Code:
    1. void SomeClass::on_http_responseHeaderReceived( const QHttpResponseHeader &h){
    2. int code = h.statusCode();
    3. if(code>=300 && code<400 && h.hasKey("location")){
    4. http->get(h.value("location"));
    5. return;
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

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

    patrik08 (17th April 2007)

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    Quote Originally Posted by wysota View Post
    Why are you complicating things so much? This should work:

    Qt Code:
    1. void SomeClass::on_http_responseHeaderReceived( const QHttpResponseHeader &h){
    2. int code = h.statusCode();
    3. if(code>=300 && code<400 && h.hasKey("location")){
    4. http->get(h.value("location"));
    5. return;
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    is ok ... if Location lowercase or uppercase ?? Location say liveheader... and if server not having session cookie....

  7. #6
    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: how to make QHttp work with this URL

    It should be case insensitive. If you're really interested, take a look at QHttpHeader sources and see if value() is case sensitive.

  8. #7
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    wysota, thank you, it makes the HTTP example run without error message, but the file will still not be downloaded. What else should I add to it for a correct download?

  9. #8
    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: how to make QHttp work with this URL

    I can't say without knowing what's wrong. How do you handle the actual download?

  10. #9
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    Well, I just took the official HTTP example by Qt, and added your code to it:

    Qt Code:
    1. void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
    2. {
    3. // handle redirections
    4. if (responseHeader.statusCode() >= 300 &&
    5. responseHeader.statusCode() < 400 &&
    6. responseHeader.hasKey("location")) {
    7. http->get(responseHeader.value("location"));
    8. return;
    9. }
    10.  
    11. if (responseHeader.statusCode() != 200)
    12. //...
    13. }
    To copy to clipboard, switch view to plain text mode 

  11. #10
    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: how to make QHttp work with this URL

    But is that branch triggered for the redirected url or not?

  12. #11
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    Looks like that it gets to a redirection circle, i.e. site1 redirects to site2 which redirects to site1... I'm not sure how to work around this. Somehow it works only from browsers.

  13. #12
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to make QHttp work with this URL

    Sorry, I realized that there is a direct link:
    http://easynews.dl.sourceforge.net/s...ges/source.zip
    It works well with this link.

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  3. QHttp signals don't work !!
    By probine in forum Qt Programming
    Replies: 11
    Last Post: 11th January 2007, 15:02
  4. Why can't I make dynamic_cast work properly?
    By pir in forum General Programming
    Replies: 13
    Last Post: 18th July 2006, 16:17
  5. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11: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.