The key to nsurlconnection implementation of a breakpoint is to customize the range domain property of the header of the HTTP request.
Range header Field
The Range header field can request one or more child ranges of an entity. For example
Represents the first 500 bytes: bytes=0-499
Represents a second 500 byte: bytes=500-999
Represents the last 500 bytes: bytes=-500
Represents the range after 500 bytes: bytes=500-
First and last byte: Bytes=0-0,-1
Specify several ranges at the same time: bytes=500-600,601-999
However, the server can ignore this request header, and if the unconditional get contains a range request header, the response is returned as a status code of 206 (partialcontent) instead of a (OK).
Use Nsmutableurlrequest in iOS to define head fields
[CPP]View Plaincopyprint?
- Nsurl *url1=[nsurl urlwithstring:@"";
- nsmutableurlrequest* Request1=[nsmutableurlrequest REQUESTWITHURL:URL1];
- [Request1 setvalue:@"bytes=20000-" forhttpheaderfield:@"Range"];
- [Request1 Setcachepolicy:nsurlrequestreloadignoringlocalcachedata];
- NSData *returndata1 = [nsurlconnection sendsynchronousrequest:request1 returningresponse:nil Error:nil];
- [Self writetofile:returndata1 filename:@"Somepath"];
- -(void) WriteToFile: (NSData *) data filename: (NSString *) filename
- {
- NSString *filepath=[nsstring stringwithformat:@"%@", FileName];
- if ([[Nsfilemanager defaultmanager] fileexistsatpath:filepath] = = NO) {
- NSLog (@"File not exist,create it ...");
- [[Nsfilemanager Defaultmanager] Createfileatpath:filepath contents:nil Attributes:nil];
- }Else {
- NSLog (@"file exist!!!");
- }
- FILE *file = fopen ([fileName utf8string], [@"ab+" utf8string]);
- if (file! = NULL) {
- fseek (file, 0, seek_end);
- }
- int readsize = [data length];
- Fwrite ((const void *) [data bytes], readsize, 1, file);
- fclose (file);
- }
iOS implements a breakpoint continuation nsurlconnection