QNetworkReply and error 202
-
HI to all
i don't understand because if i download i file from a link with my browsers i can get it and with my qt application i have always Error 202 (actaully analyzing with wireshark i got 403: permission denied as response)...is there something i'm ignoring?
i can paste my code here:
@bool YtDownloader::getFile()
{
url = "some_address_here" ;video = false; QString local = QFileInfo( url.path() ).fileName(); if(local.isEmpty()) { local = "get.out"; } file.setFileName(local); if(!file.open(QIODevice::WriteOnly)) { ui->lbDownloaded->setText("Error opening info file"); return false; } request.setUrl( url ); ui->btnDownload->setEnabled(false); startDownload(); return true;
}
void YtDownloader::startDownload()
{reply = manager->get(request); if(video) { ui->lbDownloaded->setText("Downloadingf file"); } else { ui->lbDownloaded->setText("Downloading info"); } connect(reply,SIGNAL(readyRead()),this,SLOT(scriviBytes())); connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished())); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadBar(qint64, qint64))); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(printNotOk(QNetworkReply::NetworkError)));
}
void YtDownloader::downloadFinished()
{
QVariant possibleRedirectUrl=reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if(!possibleRedirectUrl.toString().isEmpty())
{
url = reply->url();
file.close();
QFile::remove(file.fileName());
QString filename = QFileInfo( url.path() ).fileName();
file.setFileName(filename);
if(!file.open(QIODevice::WriteOnly))
{
ui->lbDownloaded->setText("Error opening file after redirectt");
return ;
}
request.setUrl(possibleRedirectUrl.toString());
startDownload();
}
else
{
reply->close();
file.write(reply->readAll());
file.close();
reply->deleteLater();
ui->btnDownload->setEnabled(true);
if(video)
{
ui->lbDownloaded->setText("File Downloaded");
emit done();
}
else
{
ui->lbDownloaded->setText("Info Downloaded");
replaceFile();
}
}
}@My app downloads a file from internet, opens it (with replaceFile() and gets real file address...and when i try to get the file (not more the info file) i get error 202...but I tried with my browser and the link is correct! help me :)
-
Are you trying to build a youtube downloader?
I don't know exactly how youtube provides content, I suggest you observe how some downloaders do their http queries against the site. -
you guessed, but analyzing chrome http request with wireshark i didn't notice nothing unusual...my application receive 403 error immediatly after 'get' request...i thought it was a user-agent problem, but i have copied chrome ones...
anyway QNAM maintains cookies automatically and represents it when asked by the server, doesn't it?