I am trying to parse JSON, and getting a SIGABRT Error: reason: '[<NSURLRequest 0x7e7e970> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Content-Type.
My code is:
self.responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://dmsfw01.dev.com:8082/G.FQI/GVOLFQI.svc/Search(v)?Start=1&Count=10"]];
NSString *contentType = @"application/json";
[request setValue:contentType forKey:@"Content-Type"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
What should I do instead to set the Content-Type?
You are getting an error because you are using a Key Value Coding method that tries to set a property on request with the name Content-Type
. Also you can not modify an NSURLRequest
because it is immutable. Use an NSMutableURLRequest
instead and then call - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://sw730voldmsfw01.vol1dev.com:8082/GVOL.FQI/GVOLFQI.svc/Search(visa)?Start=1&Count=10"]];
NSString *contentType = @"application/json";
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.