PDA

View Full Version : demo project downloadmanager: result is '301 moved permanently' or zero byte file



JeanC
20th March 2011, 11:56
Hello,

I'm trying the 'network download' demo project .

The url I give it is valid, it's something like "http://nzbmatrix.com/api-nzb-download.php?id=1234&username=xx&apikey=yy"
Unfortunately I can't give the exact url because it contains my inlog data.

I don't get the file though, I get a file with a redirect message. When I enter the url in the browser it downloads.

Something similar happens when I try to download a file from my own website, url = "http://www.jcremers.com/dl.php?file=SetupPlanetdance4.0.exe"

It downloads a 0 byte file.

How is this done?
Thanks.

squidge
20th March 2011, 12:08
A web browser would download the redirect message and then goto the address indicated in the redirect. I don't think the demo projects support such requests. A redirection can be detected by looking for a http response code 3xx.

JeanC
20th March 2011, 12:38
A web browser would download the redirect message and then goto the address indicated in the redirect. I don't think the demo projects support such requests. A redirection can be detected by looking for a http response code 3xx.

Yes that's what I'm doing now, looking for "<title>301 Moved Permanently</title>".
Thanks.

squidge
20th March 2011, 13:42
A better way would be to get the code from the reply like reply->attribute(QNetworkRequest::HttpStatusCodeAttribute ) and then use reply->attribute(QNetworkRequest::RedirectionTargetAttrib ute)

Actually, In fact, if RedirectionTargetAttribute is present, you know it's a redirect, as theres no reason for it to be set otherwise.