からPOSTリクエストを行っているときに、error.userInfoでこの応答を受け取りAFNetworking
ます。明らかなものが欠けているか、サーバー側で修正する必要があるかを誰かに教えてもらえますか?
リクエストがエラーで失敗しました:Error Domain = AFNetworkingErrorDomain Code = -1016 "Expected content type {(" text / json "、" application / json "、" text / javascript ")}、got text / html" UserInfo = 0x6d7a730 {NSLocalizedRecoverySuggestion =インデックステスト、AFNetworkingOperationFailingURLResponseErrorKey =、NSErrorFailingURLKey = http://54.245.14.201/、NSLocalizedDescription =期待されるコンテンツタイプ{( "text / json"、 "application / json"、 "text / javascript")}、get text / 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)}、get 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];