AFNetWorking出現code=-1016錯誤解決辦法,afnetworking-1016

來源:互聯網
上載者:User

AFNetWorking出現code=-1016錯誤解決辦法,afnetworking-1016

報錯類似:

2015-12-09 15:58:03.062 Carloans[14328:2300485] Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fe5ac728b50> { URL: http://api.lizicaifu.com/api.php?s=/Member/index.html&token=e0e9162086738e15a066daed1ff94baa&user_token=c8d353b0008099ba72fbcfea0b16f1c3 } { status code: 200, headers {
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Wed, 09 Dec 2015 07:57:58 GMT";
Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
Pragma = "no-cache";
Server = nginx;
"Transfer-Encoding" = Identity;
"X-Powered-By" = "PHP/5.5.29";
} }, NSErrorFailingURLKey=http://api.lizicaifu.com/api.php?s=/Member/index.html&token=e0e9162086738e15a066daed1ff94baa&user_token=c8d353b0008099ba72fbcfea0b16f1c3, com.alamofire.serialization.response.error.data=<7b227374 61747573 223a2d33 2c22696e 666f223a 225c7538 6266375c 75393163 645c7536 3562305c 75373637 625c7535 66353522 2c226669 72737422 3a6e756c 6c2c226c 61737422 3a224144 38444444 45322d41 4642312d 34343130 2d423536 452d3634 46434331 32303241 4134227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

1.修改內部檔案

AFURLResponseSerialization.m 這個檔案找到這句話self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; 然後把 text/html 加進去就可以了! 試試,我就是這麼乾的。

2.在外面修改

2.0已經對各種方法做了最佳化,也不需要用AFJSONRequestOperation,2.0已經內建JSON解析。 
你可以用AFHTTPRequestOperationManager解決一切問題,遇到你的這個問題,你可以像這麼寫: 
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//設定相應內容類型 
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
}]; 
2.0會對返回的JSON或者XML自動解析為字典的

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.