iOS 使用AFNetworking遇到錯(cuò)誤 Request failed: unacceptable content-type: text/html
錯(cuò)誤日志:
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f999be478d0> { URL: myUrlXXXXXX } { 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; charset=utf-8";**
** Date = "Tue, 24 Nov 2015 09:06:04 GMT";**
** Expires = "Thu, 19 Nov 1981 08:52:00 GMT";**
** Pragma = "no-cache";**
** Server = "nginx/1.1.19";**
** "Set-Cookie" = "PHPSESSID=qdvtek1k91oeva2u8fats39l93; path=/";**
** "Transfer-Encoding" = Identity;**
** "X-Powered-By" = "PHP/5.3.10-1ubuntu3.21";**
} }, NSErrorFailingURLKey=http:URL: myUrlXXXXXX, com.alamofire.serialization.response.error.data=<7b226572 726f725f 636f6465 223a302c 22657272 6f725f6d 7367223a 22222c22 75706c6f 61645f75 726c223a 22687474 703a5c2f 5c2f7777 772e7467 7370792e 636f6d5c 2f6c6f6f 70657273 5c2f7365 72766572 5c2f6269 6e5c2f63 7573746f 6d65725c 2f75706c 6f61645c 2f373332 31746f75 7869616e 672e6a70 67227d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}
原因:
不可接受的內(nèi)容類型 “text/html”
解決方案:
AFJSONResponseSerializer.m中她君,222行左右
把 這句: self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
修改為:
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
在進(jìn)行網(wǎng)絡(luò)請求時(shí)出現(xiàn)-1016 是因?yàn)橹恢С?br>
text/json杆逗,application/json,text/javascript
你可以添加text/html
一勞永逸的方法是 在
AFURLResponseSerialization.h
里面搜索
self.acceptableContentTypes
然后 在里面 添加
@"text/html",@"text/plain"
這樣就可以解決-1016的錯(cuò)誤了
但是隨之而來的是3840錯(cuò)誤
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
你會發(fā)現(xiàn)出現(xiàn)此錯(cuò)誤
怎么辦呢
添加如下語句 就可以解決問題了
manger.requestSerializer= [AFHTTPRequestSerializerserializer];