Tôi nhận được phản hồi này do nhầm lẫn.userInfo khi thực hiện yêu cầu POST từ AFNetworking
. Bất cứ ai có thể nói hoặc là tôi thiếu bất cứ điều gì rõ ràng hoặc một cái gì đó cần phải sửa chữa ở cuối máy chủ của tôi?Yêu cầu AFNetworking và POST
Request Failed with Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {( "text/json", "application/json", "text/javascript")}, got text/html" UserInfo=0x6d7a730 {NSLocalizedRecoverySuggestion=index test, AFNetworkingOperationFailingURLResponseErrorKey=, NSErrorFailingURLKey=http://54.245.14.201/, NSLocalizedDescription=Expected content type {( "text/json", "application/json", "text/javascript")}, got text/html, AFNetworkingOperationFailingURLRequestErrorKey=http://54.245.14.201/>}, { AFNetworkingOperationFailingURLRequestErrorKey = "http://54.245.14.201/>"; AFNetworkingOperationFailingURLResponseErrorKey = ""; NSErrorFailingURLKey = "http://54.245.14.201/"; NSLocalizedDescription = "Expected content type {(\n \"text/json\",\n \"application/json\",\n
\"text/javascript\"\n)}, got text/html"; NSLocalizedRecoverySuggestion = "index test"; }
Và tôi đang sử dụng mã này;
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];
một yêu cầu, tại sao bạn có "[operation waitUntilFinished];"? Đây có phải là cần thiết và nó là một cuộc gọi chặn? Cảm ơn! :) – trillions
vì vậy ... ở đâu/như thế nào trong mã trên bạn đã thực hiện các giải pháp được chấp nhận? – Morkrom