我从 error.userInfo 发出 POST 请求时收到此响应AFNetworking
。谁能告诉我缺少任何明显的东西或需要在我的服务器端修复的东西?
请求失败并出现错误:错误域 = AFNetworkingErrorDomain 代码 =-1016 “预期的内容类型 {(“text/json”、“application/json”、“text/javascript”)},得到了 text/html”UserInfo=0x6d7a730 {NSLocalizedRecoverySuggestion=索引测试,AFNetworkingOperationFailingURLResponseErrorKey=,NSErrorFailingURLKey=http://54.245.14.201/,NSLocalizedDescription=预期内容类型{(“text/json”,“application/json”,“text/javascript”)},得到文本/html,AFNetworkingOperationFailingURLRequestErrorKey =http://54.245.14.201/>}, { AFNetworkingOperationFailingURLRequestErrorKey = "http://54.245.14.201/>"; AFNetworkingOperationFailingURLResponseErrorKey = ""; NSErrorFailingURLKey = "http://54.245.14.201/" ; NSLocalizedDescription = "预期的内容类型 {(\n \"text/json\",\n \"application/json\",\n
\"text/javascript\"\n)}, 得到了 text/html"; NSLocalizedRecoverySuggestion = "index test"; }
我正在使用这段代码;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"Ans", @"name",
@"29", @"age",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Success");
NSLog(@"%@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
NSLog(@"Failure");
}];
[operation start];
[operation waitUntilFinished];