Reputation: 1
NSURL *url = [NSURL here`URLWithString:@"http://testing.appspot.com/json/ListingBusinessService/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFJSONParameterEncoding;
NSDictionary *params = @{@"params":@"women",@"params" : @"women", @"params":@"women"};
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
[httpClient
postPath:@"getNewArrivalProductDetailsWithPaginationForIosApp"
parameters:params
success:^(AFHTTPRequestOperation *operation,id responseObject)
{
NSLog(@"%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"%@",error);
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Data"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}
];
I am getting following error while executing above code like AFNetworkingOperationFailingURLRequestErrorKey , i guess i missing something in parameters, please suggest me in this, Thanks in advance.
Upvotes: 0
Views: 86
Reputation: 578
After calling this URL with curl from the commandline I'd say the problem is that the response content type is text/plain instead of application/json. A AFJSONRequestOperation expects the application/json ContentType.
< HTTP/1.1 200 OK
< X-TraceUrl: /appstats/details?time=1390399595248&type=json
< Content-Type: text/plain; charset=UTF-8
< Accept-Ranges: bytes
< Vary: Accept-Encoding
< Date: Wed, 22 Jan 2014 14:06:35 GMT
* Server Google Frontend is not blacklisted
< Server: Google Frontend
< Cache-Control: private
< Alternate-Protocol: 80:quic
< Transfer-Encoding: chunked
Upvotes: 1