最近上傳json格式的base64 image 出現(xiàn)了以下幾個錯誤阎毅,mark下
NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解決方法
使用AFNetworking請求出現(xiàn)了以下錯誤
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x7f8608dea390 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response= { URL: http://120.76.142.118:8080/nursery/api/login/updateheadportrait } { status code: 500, headers {
Connection = close;
"Content-Encoding" = gzip;
"Content-Language" = en;
"Content-Type" = "text/html;charset=utf-8";
Date = "Thu, 26 May 2016 11:20:51 GMT";
Server = "Apache-Coyote/1.1";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
} }
解決方法:
修改AFNetworking中AFURLResponseSerialization.m文件
在223行,將
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript", nil];
改成
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"text/json",@"text/javascript", nil];
增加了一個@"text/html"
不過因為AFNetWorking 一直在更新方仿,所以最好從外部接口調(diào)入,方法如下:
AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManagermanager];
manager.responseSerializer.acceptableContentTypes=[NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",nil,nil];
//這時又報了以下錯誤:
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set."
這時加上代碼:
manager.responseSerializer = [AFHTTPResponseSerializer serializer]
但是又報上了新的錯誤
Code=-1011 "Request failed: internal server error (500)
暫時還未找到方法,網(wǎng)上挺多說是后臺的問題,明天問問看,未完待續(xù)蹲蒲。