Alamofire.AFError.responseValidationFailed

Posted

技术标签:

【中文标题】Alamofire.AFError.responseValidationFailed【英文标题】: 【发布时间】:2017-04-03 07:21:18 【问题描述】:

遇到错误...我不知道如何解决它请帮助我

APIError<jsonError>(request: Optional(https://www.abcd.com/mobile_app/cell_action.php/?action=brand_slider_homepage), response: Optional(<NSHTTPURLResponse: 0x60800042bd20>  URL: https://www.abcd.com/cell_app/mobile_action.php/?action=brand_slider_homepage   status code: 200, headers 
"Access-Control-Allow-Headers" = "Origin, X-Requested-With, Content-Type, Accept";
"Access-Control-Allow-Methods" = "PUT, GET, POST";
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "max-age=60, private, must-revalidate";
Connection = close;
"Content-Encoding" = gzip;
"Content-Length" = 1630;
"Content-Type" = "text/html";
Date = "Mon, 03 Apr 2017 07:17:43 GMT";
Expires = "Mon, 10 Apr 2017 07:17:43 GMT";
Server = "Apache/2.4.17 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4";
Vary = "Accept-Encoding,User-Agent";
"X-Powered-By" = "PHP/5.5.30";
 ), data: Optional(16487 bytes), error: Optional((Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType(acceptableContentTypes: ["application/json"], responseContentType: "text/html"))), errorModel: Optional(abcd.HomeBrandVIewCell.jsonError))

提前

【问题讨论】:

【参考方案1】:

当您设置并期望 json 时,服务器会发送“text/html”作为响应:

acceptableContentTypes: ["application/json"], responseContentType: "text/html"

然后您需要自定义您的 HTTP 正文。在 GitHub 中试试这个链接: urlrequestconvertible

【讨论】:

以上是关于Alamofire.AFError.responseValidationFailed的主要内容,如果未能解决你的问题,请参考以下文章