AFNetworking 錯誤 Request failed: unacceptable content-type: text/plain

今天做連接api獲取數據的時候發現以下錯誤:

error: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0x17d0ccb0 {NSErrorFailingURLKey=http://192.168.1.34:8080/SpringREST/api/driverLogin/123/abc, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x17d14480> { URL: http://192.168.1.34:8080/SpringREST/api/driverLogin/123/abc } { status code: 200, headers {
    "Content-Length" = 156;
    Date = "Thu, 16 Apr 2015 06:29:34 GMT";
    Server = "Apache-Coyote/1.1";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}


參考網上提供的修改方法:
需要在AF的源文件AFURLResponseSerialization.m中添加以下紅色部分代碼,添加@"text/plain"類型
相關代碼:

- (instancetype)init {
    self = [super init];
    if (!self) {
        return nil;
    }
   self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", @"text/json", @"text/javascript",@"text/plain", nil];

    return self;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章