AFNetworking 3.0.4 Error:"Request failed: unacceptable content-type: text/html"

使用AFNetWorking上传内容+参数,

 1 NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://example.com/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
 2         [formData appendPartWithFileURL:[NSURL fileURLWithPath:@"file://path/to/image.jpg"] name:@"file" fileName:@"filename.jpg" mimeType:@"image/jpeg" error:nil];
 3     } error:nil];
 4
 5 AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
 6
 7 NSURLSessionUploadTask *uploadTask;
 8 uploadTask = [manager
 9               uploadTaskWithStreamedRequest:request
10               progress:^(NSProgress * _Nonnull uploadProgress) {
11                   // This is not called back on the main queue.
12                   // You are responsible for dispatching to the main queue for UI updates
13                   dispatch_async(dispatch_get_main_queue(), ^{
14                       //Update the progress view
15                       [progressView setProgress:uploadProgress.fractionCompleted];
16                   });
17               }
18               completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
19                   if (error) {
20                       NSLog(@"Error: %@", error);
21                   } else {
22                       NSLog(@"%@ %@", response, responseObject);
23                   }
24               }];
25
26 [uploadTask resume];

上传成功,但是返回错误信息:

 1 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x14a8ceb90> { URL: http://www.test.com/upload.html } { status code: 200, headers {
 2     "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
 3     Connection = "keep-alive";
 4     "Content-Length" = 272;
 5     "Content-Type" = "text/html;charset=utf-8";
 6     Date = "Tue, 05 Jan 2016 03:10:06 GMT";
 7     Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
 8     Pragma = "no-cache";
 9     "Set-Cookie" = "SERVERID=8ea4a47cd3afa7bf20d29833f1a0f41f|1451963396|1451963392;Path=/";
10     "X-Powered-By" = "PHP/5.5.9";
11 } }, NSErrorFailingURLKey=http://www.c-cam.cc/index.php/Api/Uploadphoto/upload.html, com.alamofire.serialization.response.error.data=<5b312c22 68747470 3a5c2f5c 2f696d67 6363616d 2e632d63 616d2e63 635c2f69 6d616765 5c2f5c2f 616c6275 6d5c2f32 30313630 3130355c 2f616230 38613039 36303134 30393635 32323834 38306135 39666665 35623366 642e6a70 67222c22 68747470 3a5c2f5c 2f696d67 6363616d 2e632d63 616d2e63 635c2f69 6d616765 5c2f5c2f 73686172 655c2f32 30313630 3130355c 2f616230 38613039 36303134 30393635 32323834 38306135 39666665 35623366 642e6a70 67222c22 68747470 3a5c2f5c 2f777777 2e632d63 616d2e63 635c2f69 6e646578 2e706870 5c2f4669 7273745c 2f576f72 6b5c2f70 686f746f 5f646574 61696c5c 2f776f72 6b69645c 2f313434 38342e68 746d6c22 2c22225d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}

之前遇到过,又跳进了老坑,答案在这里

只需要在AFURLResponseSerialization.m的acceptableContentTypes中,添加text/html类型。

 1 ...
 2
 3 - (instancetype)init {
 4     self = [super init];
 5     if (!self) {
 6         return nil;
 7     }
 8
 9     self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
10
11     return self;
12 }
13
14 ....

参考:http://stackoverflow.com/questions/19114623/request-failed-unacceptable-content-type-text-html-using-afnetworking-2-0

时间: 2024-10-24 01:51:25

AFNetworking 3.0.4 Error:"Request failed: unacceptable content-type: text/html"的相关文章

AFNetworking 遇到错误 Code=-1016 &quot;Request failed: unacceptable content-type: text/plain&quot;

在开发过程使用了AFNetworking库,版本2.x,先运行第一个官方例子(替换GET 后面的url即可): AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operatio

[原]Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable con

转载请注明出处:http://blog.csdn.net/dengbin9009/article/details/43485617 在使用AFNetworking 2.0  的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed:

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable content-type: text/html&quot; 的问题原因及解决方案

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html",此问题的原因就是使用的第三方框架AFNetworking 接口返回值类型不确定,由于服务器人员习惯于使用html文件所以将json文件也这么写了,导致没法解析 在模型类或者网络工具类中添加这句代码就能完美解决上述问题,建议不要直接修改AFNetw

iOS AFNetworking “Request failed: unacceptable content-type: text/html”问题

使用AFNetworking出现报错: error=Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7fdfd8729680 {com.alamofire.serialization.response.error.response= { URL: http://172.1

AFNetworking报错:(415 Domain=com.alamofire.error.serialization.response Code=-1011 &quot;Request failed: unsupported media type (415)&quot;)

问题? 今天在与后台调接口的时候,遇到一个问题,使用AFNetworking报错,具体如下: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unsupported media type (415)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse:

iOS 使用AFNetworking遇到错误 Request failed: unacceptable content-type: text/html

错误日志: 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: myUrlX

iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html

错误日志是: Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fc8b970eb70> { URL: http:

NSLocalizedDescription=Request failed: unacceptable content-type: text/html 解决方法

使用AFNetworking请求一个网站出现了以下错误 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fc688f3

iOS&quot;Request failed: unacceptable content-type: text/html&quot;

以前用的好端端的接口,今天访问居然出错了,但是再用浏览器测试,发现可以正常返回数据,甚是奇怪啊. 下面是错误信息: 获取服务器响应出错 error=ErrorDomain=com.alamofire.error.serialization.response Code=-1016"Request failed: unacceptable content-type: text/html"UserInfo=0x7fdfd8729680{com.alamofire.serialization.