I am writing a utility that allow开发者_如何学Gos users to download large files from my server. I need the user to have the flexibility to pause and resume a download request through a button click. I am using ASIHTTPRequest library, however it doesn;t provide any API to pause a request. (There are routines to resume a download request). Is canceling a download request only way to pause a request.
Thanks
Most servers support the HTTP range header. You can use this to specify the offset from which you’re requesting on resume.
There is no direct way to pause downloading. This can be achieved using range header of HTTP protocol.
Read here for details....
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16
Setting range property in request header will do. For knowing how to set request header in Library you are using read the documentation.
following would be the way parameter to pass in range.
NSString* range = @"bytes=";
range = [range stringByAppendingString:[[NSNumber numberWithInt:offset] stringValue]];
range = [range stringByAppendingString:@"-"];
[request setValue:range forHTTPHeaderField:@"Range"];
Use NSMutableRequest and NSURLConnection if you want to use abuve code
精彩评论