错误域= NSURLErrorDomain代码= -1017“无法解析响应”

问题描述:

我发布json时收到错误。

Here I am getting error while I post json.


错误域= NSURLErrorDomain Code = -1017无法解析响应UserInfo = 0x7f89dac01a40 {NSUnderlyingError = 0x7f89e0277a20无法解析响应,NSErrorFailingURLStringKey = http://test-onboard.qlc。 in / FieldSense / authenticate ,NSErrorFailingURLKey = http://test-onboard.qlc.in / FieldSense / authenticate ,_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -1,NSLocalizedDescription =无法解析响应}

Error Domain=NSURLErrorDomain Code=-1017 "cannot parse response" UserInfo=0x7f89dac01a40 {NSUnderlyingError=0x7f89e0277a20 "cannot parse response", NSErrorFailingURLStringKey=http://test-onboard.qlc.in/FieldSense/authenticate, NSErrorFailingURLKey=http://test-onboard.qlc.in/FieldSense/authenticate, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-1, NSLocalizedDescription=cannot parse response}

这是我的代码:

NSDictionary *dictionaryData=[[NSDictionary alloc]initWithObjectsAndKeys:self.txtUsername.text, @"userEmailAddress", self.txtPassword.text, @"password",nil];            
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictionaryData options:kNilOptions error:&error];

[request setURL:url];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:jsonData];


我也遇到了这个错误,但我克服了这一点添加一行

I am also getting this error but i overcome this by adding a line

request.HTTPMethod = "POST"

用于Objective-C编程使用:

for Objective-C programming use this:

[request setHTTPMethod:@"POST"];