AFNetworking y solicitud POST
Recibo esta respuesta en error.userInfo al realizar una solicitud POST deAFNetworking
. ¿Alguien puede decir que me estoy perdiendo algo obvio o que algo debo arreglar en el extremo de mi servidor?
Solicitud fallida con error: Error Dominio = AFNetworkingErrorDomain Code = -1016 "Tipo de contenido esperado {(" text / json "," application / json "," text / javascript ")}, got text / html" UserInfo = 0x6d7a730 {NSLocalizedRecoverySuggestion = index test, AFNetworkingOperationFailingURLResponseErrorKey =, NSErrorFailingURLKey = http: //54.245.14.201/, NSLocalizedDescription = Tipo de contenido esperado {("text / jtp" = http: //54.245.14.201/>}, {AFNetworkingOperationFailingURLRequestErrorKey = "http://54.245.14.201/>"; AFNetworkingOperationFailingURLResponseErrorKey = ""; NSErrorFailingURLKey = "http://54.245.14.201/"; NSLocalizedDescription = "Tipo de contenido esperado {(\ n \" text / json \ ", \ n \" application / json \ ", \ n
\ "texto / javascript \" \ n)}, got text / html "; NSLocalizedRecoverySuggestion =" prueba de índice ";}
Y estoy usando este código;
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];