error for setting range for NSURLConnection, NSMutableURLRequest
I am trying to implement download resuming functionality by using setValue:forHTTPHeaderField. But whenever I use that method, I get an
[NSURLRequest setValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x4e0b710 2011-08-08 22:44:36.469 Patch[9140:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest setValue:forHTTPHeaderField:]: unrecognized selector sent to instance 0x4e0b710'
error.
My code works fine without that method but when I include this code, I get the error above
NSMutableURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]
cachePolicy:NSURLRequestUseProto开发者_开发问答colCachePolicy
timeoutInterval:60.0];
//---------------- setting range for download resume -----------------------
NSString* range = @"bytes=";
range = [range stringByAppendingString:[[NSNumber numberWithInt:offset] stringValue]];
range = [range stringByAppendingString:@"-"];
NSLog(@"range: %@", range);
[request setValue:range forHTTPHeaderField:@"Range"];
please help me... Thank you very much
You need to create an NSMutableURLRequest
with an NSMutableURLRequest
.
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
精彩评论