Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error for setting range for NSURLConnection, NSMutableURLRequest

Tags:

iphone

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:NSURLRequestUseProtocolCachePolicy
                                     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

like image 703
BK Choi Avatar asked Aug 08 '11 13:08

BK Choi


1 Answers

You need to create an NSMutableURLRequest with an NSMutableURLRequest.

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]
                                         cachePolicy:NSURLRequestUseProtocolCachePolicy
                                     timeoutInterval:60.0];
like image 171
Joe Avatar answered Nov 26 '22 08:11

Joe