【发布时间】:2017-04-28 18:54:57
【问题描述】:
我在我的 Objective c 应用程序中使用来自 github 的 JSONHTTPClient 库。我对我的 api 进行了很多调用并且一切正常,但是当我尝试添加带有标题和正文的 POST 函数时,我收到一个错误:
Error Domain=JSONModelErrorDomain Code=2 "网络响应错误。 JSON URL 可能无法访问。” UserInfo={NSLocalizedDescription=网络响应错误。大概是 JSON URL 无法访问。}
我使用 JSONFromURLWithString url 进行 POST 调用。 api调用正常工作,从服务器返回数据(我从邮递员那里测试过)但是从我的目标c应用程序中的这个函数我总是得到错误,为什么不得到响应?
我是否发送了任何格式错误的数据?
这是我的代码:
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"var1", @"keyVar1", @"5" , @"keyvar2", nil];//Here initialize my headers values into a dictionary
NSDictionary *dicty = [NSDictionary dictionaryWithObjectsAndKeys:@"6234", @"id", @"4324" , @"id2", nil];//This is my body
NSData *jsonDatass = [NSJSONSerialization dataWithJSONObject:dicty options:0 error:nil];//Here convert my body to nsdata
[JSONHTTPClient JSONFromURLWithString:@"myURL" method:@"POST" params:nil orBodyData:jsonData headers:parameters completion:^(id json, JSONModelError *err){
NSLog(@"have error?: %@", err);
NSLog(@"have response?: %@", json);
}];
【问题讨论】:
标签: ios objective-c json post jsonhttpclient