Qt- resuming http download and resending http request
-
first ,I paused the downloading process without closing my application ,a few minutes later ,if I want to resume the download again ,do I have to send a second request to the sever ?
as far as I know ,the http connection will keep alive for a while after the downloading process is paused , so there is no need to resend a request to the sever again ,right ?
In Qt, how can we pause the downloading process? which method should we use ? QNetworkReply::close() or QNetworkReply::abort() or other ways ?
if the http connection still keeps alive, is it possible to resume the http download without resending http request to the sever ? It would be better to show me some code on implementing this ,thanks.
-
Http is a stateless protocol. You're either receiving data or not and there is no pausing. This effect can be simulated though.
First of all server needs to support few things. It must send the size of resource as one of the response headers and it needs to support range headers in requests. Most servers do.To "pause" you should just call abort(), as close() just closes the IODevice and doesn't actually stop the transfer. You should also store somewhere the size of the resource from the response header and the size of the data you already downloaded.
To "resume" you make another request using the "range http header":http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 with a range corresponding to the remaining part. -
[quote author="Chris Kawa" date="1384685415"]Http is a stateless protocol. You're either receiving data or not and there is no pausing. This effect can be simulated though.
First of all server needs to support few things. It must send the size of resource as one of the response headers and it needs to support range headers in requests. Most servers do.To "pause" you should just call abort(), as close() just closes the IODevice and doesn't actually stop the transfer. You should also store somewhere the size of the resource from the response header and the size of the data you already downloaded.
To "resume" you make another request using the "range http header":http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35 with a range corresponding to the remaining part.[/quote]
http://qt-project.org/forums/viewthread/35211/