[英]Content-Type JSON SIGABRT Error
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.
我试图解析JSON,并收到SIGABRT错误:
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? 我应该怎么做才能设置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
. 由于使用的键值编码方法尝试根据请求设置名称为
Content-Type
的属性,因此出现错误。 Also you can not modify an NSURLRequest
because it is immutable. 另外,您不能修改
NSURLRequest
因为它是不可变的。 Use an NSMutableURLRequest
instead and then call - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
. 请改用
NSMutableURLRequest
,然后为- (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field
调用- (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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.