8、使用AFNetwroking請求錯誤 輸出Bug

1、錯誤:請求錯誤時,error錯誤信息如下,這樣我們找不出錯誤原因,無法展示給用戶。

Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: client error (422)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f9210fb3d20> { URL: http://xxxxxxx.com/orders/cash_search.json } { status code: 422, headers {
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Tue, 12 Apr 2016 05:43:01 GMT";
    Server = "nginx/1.6.2";
    "Transfer-Encoding" = Identity;
    Vary = Origin;
    "X-Frame-Options" = ALLOWALL;
    "X-Request-Id" = "as6778e2-fdc7-43ee-a29e-24d264a513a1";
    "X-Runtime" = "0.050252";
} }, NSErrorFailingURLKey=http://xxxxxxxx.com/orders/cash_search.json, com.alamofire.serialization.response.error.data=<7b226d65 73736167 65223a22 e69caae6 89bee588 b0e8aea2 e58d9521 227d>, NSLocalizedDescription=Request failed: client error (422)}

2、解決:在網上查了好多資料,有人說是加如下代碼:可還是不對

//---------
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html", nil];
//---------

最后加了如下這樣代碼的,輸入才正常:

NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
NSLog(@"error--%@",serializedData);

3、解決原文地址:
http://stackoverflow.com/questions/26469002/afnetworking-keep-returning-response-code-1011-request-failed-client-error-4

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • error code(錯誤代碼)=0是操作成功完成。error code(錯誤代碼)=1是功能錯誤。error c...
    Heikki_閱讀 3,457評論 1 9
  • error code(錯誤代碼)=2000是無效的像素格式。error code(錯誤代碼)=2001是指定的驅動...
    Heikki_閱讀 1,874評論 0 4
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,991評論 19 139
  • 最近上傳json格式的base64 image 出現了以下幾個錯誤,mark下 NSLocalizedDescri...
    AlenChen閱讀 10,036評論 7 50
  • 項目組件化、平臺化是技術公司的共同目標,越來越多的技術公司推崇使用pod管理第三方庫以及私有組件,一方面使項目架構...
    swu_luo閱讀 22,282評論 0 39