2014-01-22 64 views
0
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]; 
       } 
    ]; 

我越來越而像上面這樣AFNetworkingOperationFailingURLRequestErrorKey代碼執行下面的錯誤而失敗,我想我失去了一些東西在參數,請建議我在這,在此先感謝。AFNetworking在Java Web服務

+0

這段代碼的上下文是什麼?你試過什麼解決方案?請詳細說明您的問題,以獲得更好的幫助! –

+0

什麼是錯誤?什麼不工作? –

+0

我得到錯誤像AFNetworkingOperationFailingURLRequestErrorKey,錯誤它的打印整個JSON,但在失敗塊 – user2667982

回答

1

從命令行使用curl調用此URL後,我會說問題是響應內容類型是text/plain而不是application/json。 AFJSONRequestOperation需要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 
+0

感謝您的答覆,並且我已經更新與應用程序/ JSON代碼,但我是獲取失敗消息 – user2667982

+0

我只是再次嘗試訪問該URL,現在我得到一個HTTP302和contentType ist文本/ HTML – rist