AFNetworking und POST-Anforderung
Ich erhalte diese Antwort in error.userInfo, während ich eine POST-Anfrage von stelleAFNetworking
. Kann jemand sagen, ob ich etwas Offensichtliches vermisse oder etwas, das auf meinem Server behoben werden muss?
Anfrage fehlgeschlagen mit Fehler: Fehler Domain = AFNetworkingErrorDomain Code = -1016 "Erwarteter Inhaltstyp {(" text / json "," application / json "," text / javascript ")}, erhaltener Text / html" UserInfo = 0x6d7a730 {NSLocalizedRecoverySuggestion = Indextest, AFNetworkingOperationFailingURLResponseErrorKey =, NSErrorFailingURLKey = http: //54.245.14.201/, NSLocalizedDescription = Erwarteter Inhaltstyp {("text / json", "application / json", "text / javascript", "application / json", "text / javascript")} = http: //54.245.14.201/>}, {AFNetworkingOperationFailingURLRequestErrorKey = "http://54.245.14.201/>"; AFNetworkingOperationFailingURLResponseErrorKey = ""; NSErrorFailingURLKey = "http://54.245.14.201/"; NSLocalizedDescription = "Erwarteter Inhaltstyp {(\ n \" text / json \ ", \ n \" application / json \ ", \ n
\ "text / javascript \" \ n)}, habe text / html "; NSLocalizedRecoverySuggestion =" index test ";}
Und ich benutze diesen Code;
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];