PDA

View Full Version : QHttpRequestHeader download from 1 byte to 1000 byte - part File ?



nhs_0702
19th April 2010, 10:26
void HttpWindow::resumeDownloadFile()
{
QString qEditUrl = urlLineEdit->text();
QFileInfo fileInfo(qEditUrl);
QString fileName = fileInfo.fileName();
if (fileName.isEmpty())
fileName = "index.html";
QUrl subjectUrl(qEditUrl);
qfFileOut = new QFile(fileName);
if(!qfFileOut->open(QIODevice::WriteOnly)){
return;
}
QHttpRequestHeader qHeader;
http->setHost(subjectUrl.host());
qHeader.setRequest("GET", subjectUrl.path());
qHeader.addValue("Host", subjectUrl.host());
qHeader.addValue("Range", QString("bytes=1-1000"));
httpRequestAborted = false;
httpGetId = http->request(qHeader, 0, qfFileOut);
progressDialog->setWindowTitle(tr("HTTP"));
progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
downloadButton->setEnabled(false);
}



void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
switch (responseHeader.statusCode()) {
case 200: // Ok
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307:
break;// Temporary Redirect
default:
QMessageBox::information(this, tr("HTTP"),tr("Error Response Header : %1.").arg(responseHeader.reasonPhrase()));
httpRequestAborted = true;
progressDialog->hide();
//http->abort();
}
}


i want download 1 file from 1 byte -> 1000 byte ,dont download all,i use funciton
qHeader.addValue("Range", QString("bytes=1-1000"));
but it error :





http://c.upanh.com/upload/5/319/VZ0.9474636_1_1.png

wysota
19th April 2010, 10:40
So? Did you check the reason?

squidge
19th April 2010, 14:34
Some servers may not support the 'Range' header. This will be stated in the statusCode.

wysota
19th April 2010, 15:16
He's getting a 404, so it's not about an unhandled header but rather about a wrong path to the resource.