0
我必須向我的服務器發送郵件請求,需要JSOn。我使用下面的代碼,以請求:在網絡傳遞中獲取JSON響應錯誤
AFHTTPClient* httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:SERVER_URL]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
NSMutableURLRequest *jsonRequest = [httpClient requestWithMethod:@"POST" path:@"/" parameters:@{@"name":@"piggy"}];
AFJSONRequestOperation *operation2 = [AFJSONRequestOperation JSONRequestOperationWithRequest:jsonRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"RECEIVED: %@ ", JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
//NSLog(@"GGG:%@",JSON);
}];
但我得到的錯誤:
2013-04-11 11:07:40.089連接
Request Failed with Error: Error Domain=com.alamofire.networking.error Code=-1016 "Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html" UserInfo=0xad8c6e0 {NSLocalizedRecoverySuggestion=
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
}
可能是請求的問題?但是有什麼問題? – user1374408 2013-04-11 06:23:35
我的意思是你的服務器可能有問題。您可能無法正確處理請求,因此您的服務器響應是HTML,而不是使用JSON響應。 – calampunay 2013-04-11 06:28:55
服務器的預期響應是什麼?它應該用JSON數據迴應嗎? – calampunay 2013-04-11 06:32:43