2014-01-15 99 views
3

我發送一個GET請求的URL是這樣的:https://test.com/app/login?json={"user":"[email protected]","password":"test"}AFHTTPRequestOperationManager Get請求失敗,錯誤域= AFNetworkingErrorDomain代碼= -1016

,但這個錯誤:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0x9ad3520 {NSErrorFailingURLKey=https://test.com/app/login?json=%7B%22user%22:%[email protected]%22,%22password%22:%22test%22%7D, AFNetworkingOperationFailingURLResponseErrorKey= { URL: https://test.com/app/login?json=%7B%22user%22:%[email protected]%22,%22password%22:%22test%22%7D } { status code: 200, 

    headers { 
    "Cache-Control" = "max-age=900"; 
    Connection = "Keep-Alive"; 
    "Content-Length" = 6116; 
    "Content-Type" = "text/plain; charset=UTF-8"; 
    Date = "Wed, 15 Jan 2014 09:14:22 GMT"; 
    Expires = "Wed, 15 Jan 2014 09:29:22 GMT"; 
    "Keep-Alive" = "timeout=2, max=100"; 
    Server = "Apache-Coyote/1.1"; 
    "Set-Cookie" = "APP-SESSION-ID=xxxxxxxxxxxxxxxx; Path=/app/; HttpOnly, APP-ROUTE-ID=.app1_node2; path=/, API-ROUTE-ID=.app1_node2; path=/"; 
    } } 

, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain} 

這裏是我的代碼,我用NSUTF8StringEncoding添加了百分比轉義。

manager = [AFHTTPRequestOperationManager manager]; 
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; 
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { 

} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

}]; 
+0

使這是一個答案,並接受它自己 –

+0

@Lithu T.V感謝您的提醒。 – pyanfield

回答

8

我已經修復了這個問題。

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; 

參考:github.com/AFNetworking/AFNetworking/issues/1586

+1

我用你的代碼,並得到其他錯誤代碼= 3840。 我檢查的主機,也有api響應json類型和文本類型。 這是否會導致錯誤? 謝謝 –

相關問題