Ios 在afnetworking中获取JSON响应时出错

Ios 在afnetworking中获取JSON响应时出错,ios,afnetworking,Ios,Afnetworking,我必须向我的服务器发出一个post请求,该请求采用JSOn。我正在使用以下代码发出请求: AFHTTPClient* httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:SERVER_URL]]; [httpClient setParameterEncoding:AFJSONParameterEncoding]; NSMutableURLRequest *jsonRequest

我必须向我的服务器发出一个post请求,该请求采用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">
请求失败,错误为:Error Domain=com.alamofire.networking.Error code=-1016“预期的内容类型{(
“text/json”,
“应用程序/json”,
“文本/javascript”
)},获取text/html“UserInfo=0xad8c6e0{NSLocalizedRecoverySuggestion=

}

错误消息解释了这一点:您需要一个JSON响应,但实际响应是HTML。要么是1)您的URL错误,要么是2)您没有正确处理请求。

请求可能有问题?但什么问题?我的意思是你的服务器可能有问题。您可能没有正确处理请求,因此您的服务器响应是HTML,而不是使用JSON进行响应。您希望服务器的响应是什么?它应该用JSON数据响应吗?