0
JSOn이 필요한 서버에 게시물 요청을해야합니다. 내가 요청하기 위해 다음 코드를 사용하고 있습니다 :afnetworking에서 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년 4월 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
내가 말한 것은 서버에 문제가있을 수 있다는 것입니다. 요청을 올바르게 처리하지 못할 수 있으므로 JSON으로 응답하는 대신 서버 응답이 HTML입니다. – calampunay
서버에서 예상되는 응답은 무엇입니까? JSON 데이터로 응답해야합니까? – calampunay