ios - AFHTTPRequestOperationManager 获取请求失败,Error Domain=AFNetworkingErrorDomain Code=-1016

标签 ios afnetworking-2

我向这样的 url 发送一个 GET 请求:https://test.com/app/login?json={"user":"test@gmail.com","password":"test "

但是返回这个错误:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0x9ad3520 {NSErrorFailingURLKey=https://test.com/app/login?json=%7B%22user%22:%22test@gmail.com%22,%22password%22:%22test%22%7D, AFNetworkingOperationFailingURLResponseErrorKey= { URL: https://test.com/app/login?json=%7B%22user%22:%22test@gmail.com%22,%22password%22:%22test%22%7D } { status code: 200, 

    headers {
    "Cache-Control" = "max-age=900";
    Connection = "Keep-Alive";
    "Content-Length" = 6116;
    "Content-Type" = "text/plain; charset=UTF-8";
    Date = "Wed, 15 Jan 2014 09:14:22 GMT";
    Expires = "Wed, 15 Jan 2014 09:29:22 GMT";
    "Keep-Alive" = "timeout=2, max=100";
    Server = "Apache-Coyote/1.1";
    "Set-Cookie" = "APP-SESSION-ID=xxxxxxxxxxxxxxxx; Path=/app/; HttpOnly, APP-ROUTE-ID=.app1_node2; path=/, API-ROUTE-ID=.app1_node2; path=/";
    } }

, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}

这是我的代码,我用 NSUTF8StringEncoding 添加了百分比转义。

manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id   responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

最佳答案

我已经解决了这个问题。

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"]; 

引用:github.com/AFNetworking/AFNetworking/issues/1586

关于ios - AFHTTPRequestOperationManager 获取请求失败,Error Domain=AFNetworkingErrorDomain Code=-1016,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21136256/

相关文章:

ios - 使用 AFNetworking 从 Django 服务器下载文件

ios - -[AFHTTPRequestSerializer requestWithMethod :URLString:parameters:error:] 中的断言失败

php - AFNetworking 将 UIImage 上传为 NSData -> PHP 脚本移动文件

ios - 每个图像调用 4 次 SDWebImage Complete 闭包

iphone - 项目构建没有错误但未运行

架构 x86_64 的 IOS undefined symbol

ios - AFNetworking 2.0 多部分请求正文空白

ios - 如何调整纵向和横向 View 的约束?

ios - 如何单击 UITabBarItem 并显示新的 ViewController?

ios - 实现 textViewDidChange :