簡體   English   中英

在AFNetworking中獲取JSON響應錯誤

[英]Getting error in JSON response in 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-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">

}

錯誤消息對此進行了解釋:您需要一個JSON響應,但實際的響應是HTML。 它要么是1)您的URL錯誤,要么是2)您沒有正確處理請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM