PDA

View Full Version : how to make QHttp work with this URL



ber_44
17th April 2007, 08:19
The HTTP example fails at this URL:
http://downloads.sourceforge.net/isisimages/source.zip
How to make it work?

marcel
17th April 2007, 08:21
The link is being redirected to here :
http://sourceforge.net/project/downloading.php?groupname=isisimages&filename=source.zip&use_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

patrik08
17th April 2007, 09:59
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....




void RegisterCookie(const QHttpResponseHeader &responseHeader )
{
ActualCook.clear();
QStringList cookielist = responseHeader.allValues("set-cookie");
for (int i = 0; i < cookielist.size(); ++i) {
QString cokeline = cookielist.at(i);
QStringList onlines = cokeline.split("=");
QString cookiename = onlines.at(0);
QString cookievalue = onlines.at(1);
ActualCook.insert(i,QStringList() << cookiename << Url_Decode(cookievalue) << actualurl);
/////////////////qDebug() << "### entry set-cookie pos=" << i << " name= " << cookiename << " value=" << Url_Decode(cookievalue);
}
//////////emit WatReturn(QString("One code=%1 - Other say = %2 \n%3").arg( responseHeader.statusCode() ).arg( responseHeader.reasonPhrase() ).arg(CookieVars()) );
}




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



http://downloads.sourceforge.net/isisimages/source.zip

GET /isisimages/source.zip HTTP/1.1
Host: downloads.sourceforge.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.qtcentre.org/forum//forum/newreply.php?do=postreply&t=6595
Cookie: ebNewBandWidth_.sourceforge.net=589%3A117536250326 5; __utmz=191645736.1176795478.834.46.utmccn=(referra l)|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.1 176795478.834; sso_session_ser=yKK3e8LVW6r8auGwiHUNePItpalud5j%2B 54olwzSzS4soMkSBvWa4R%2BJEPm6Wn30sQiHC17XThHPg3KMs C2qEPizzVh%2FYdN2K0Ec75%2FtfH%2B8mVoAtmF0bDYklJOqy uyLa%2B4%2BQqU5aYeW2GfRW%2FqCBbnKjYuiyNGIdc0g5ydI5 sBQ%3D-5ead3f2617584e562295ee6a3be43f78; __utmc=191645736; __utmb=191645736

HTTP/1.x 301 Moved Permanently
X-Powered-By: PHP/5.2.1
Location: http://sourceforge.net/project/downloading.php?groupname=isisimages&filename=source.zip&use_mirror=heanet
Content-Type: text/html
Content-Length: 0
Date: Tue, 17 Apr 2007 07:54:32 GMT
Server: lighttpd/1.4.15
----------------------------------------------------------

wysota
17th April 2007, 11:27
Why are you complicating things so much? :) This should work:


void SomeClass::on_http_responseHeaderReceived( const QHttpResponseHeader &h){
int code = h.statusCode();
if(code>=300 && code<400 && h.hasKey("location")){
http->get(h.value("location"));
return;
}
}

patrik08
17th April 2007, 14:11
Why are you complicating things so much? :) This should work:


void SomeClass::on_http_responseHeaderReceived( const QHttpResponseHeader &h){
int code = h.statusCode();
if(code>=300 && code<400 && h.hasKey("location")){
http->get(h.value("location"));
return;
}
}


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

wysota
17th April 2007, 14:15
It should be case insensitive. If you're really interested, take a look at QHttpHeader sources and see if value() is case sensitive.

ber_44
19th April 2007, 07:59
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?

wysota
19th April 2007, 09:20
I can't say without knowing what's wrong. How do you handle the actual download?

ber_44
20th April 2007, 04:26
Well, I just took the official HTTP example by Qt, and added your code to it:



void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
// handle redirections
if (responseHeader.statusCode() >= 300 &&
responseHeader.statusCode() < 400 &&
responseHeader.hasKey("location")) {
http->get(responseHeader.value("location"));
return;
}

if (responseHeader.statusCode() != 200)
//...
}

wysota
20th April 2007, 07:27
But is that branch triggered for the redirected url or not?

ber_44
23rd April 2007, 08:31
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.

ber_44
23rd April 2007, 10:20
Sorry, I realized that there is a direct link:
http://easynews.dl.sourceforge.net/sourceforge/isisimages/source.zip
It works well with this link.