PDA

View Full Version : Resume download with QHttp



THRESHE
17th November 2007, 16:33
Hello everyone
I'm writing an app that downloads data from the Internet ( like FlashGet or Download Master ). I need to resume download of a file. I use QHttp like


file_ = new QFile(GetDownloadName());
file_->open(QIODevice::Append);

QUrl url(downloadURL_);
http_.setHost(url.host());
http_.get(url.path(), file_);

Maybe I should use some different function like QHttp::request ?

jpn
18th November 2007, 12:22
Perhaps QHttp::request() and "Content-Range" header field?

THRESHE
19th November 2007, 12:42
Thanks. It seems that my guess was right ;)

THRESHE
19th November 2007, 13:38
It's strange I'm trying to use QHttp::request like this


file_ = new QFile(GetDownloadName());
file_->open(QIODevice::Append);

QUrl url(downloadURL_);
http_.setHost(url.host());

QHttpRequestHeader header("GET", url.path());
header.addValue("Content-Range", "bytes 21010-47021/47022");
qDebug()<<header.toString();
http_.request(header,0, file_);

But it downloads the whole file not just 21010-47021 bytes :confused:

jpn
19th November 2007, 13:45
Oops, "Content-Range" is a field of server response header. I think the corresponding client request header field is actually just "Range".

nhs_0702
17th April 2010, 06:25
i want find document funcition header.addValue("Content-Range", "bytes 21010-47021/47022");

nhs_0702
17th April 2010, 06:42
i dont known qHeader.addValue("Range", "bytes 21010-47021/47022");

nhs_0702
17th April 2010, 11:12
void BrowseWidgetImpl::downloadSubjectForNextThread()
{
if(nextThreadConnection.state() == QHttp::Reading)
{
reloadCompleted();
return;
}
nextThreadConnection.abort();
if(nextThreadBuffer)
{
delete nextThreadBuffer;
nextThreadBuffer = NULL;
}
QUrl subjectUrl(threadUrl.mid(0, threadUrl.lastIndexOf("dat/")) + "subject.txt");
// nextThreadBuffer.size(0);
nextThreadBuffer = new QBuffer;
if(!nextThreadBuffer->open(QIODevice::ReadWrite))
{
qDebug() << "Can't open buffer in downloadSubjectForNextThread()";
return;
}
QHttpRequestHeader header;
nextThreadConnection.setProxy(*networkProxy);
nextThreadConnection.setHost(subjectUrl.host());
header.setRequest("GET", subjectUrl.path());
header.addValue("Host", subjectUrl.host());
header.addValue("User-Agent", QString("Monazilla/1.00(%1)").arg(APPNAME));
subjectGetId = nextThreadConnection.request(header, 0, nextThreadBuffer);
}