Error setting range for NSURLConnection, NSMutableURLRequest

I am trying to implement a resume resume function using SetValue: forHTTPHeaderField. But whenever I use this method, I get

[NSURLRequest setValue: forHTTPHeaderField:]: unrecognized selector sent as an example 0x4e0b710 2011-08-08 22: 44: 36.469 Patch [9140: 207] * Application terminated due to an uncaught exception 'NSInvalidArgumentException', reason: '- [NSURLRequest set forHTTPHeaderField:]: unrecognized selector sent to instance 0x4e0b710

error.

My code works fine without this 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 ... thanks a lot

+6
source share
1 answer

You need to create NSMutableURLRequest with NSMutableURLRequest .

 NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
+12
source

Source: https://habr.com/ru/post/894542/


All Articles