ios - AFN Code=-1011 "Request failed: internal server error (500)
大家讲道理
大家讲道理 2017-04-17 17:47:32
0
3
1320

我的代码:

AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
[mgr.requestSerializer setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Accept"];
[mgr POST:url parameters:param success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
                    NSLog(@"上传结果:%@",responseObject);
                    
                } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
                    NSLog(@"error:%@",error);
                }];

NSDictionary *param = @{@"userid":@"4704",@"name":@"name",@"info":shj_str,@"id":@"0"};

其中shj_str是JSON字符串

请求结果error:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x156f70f70 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x15801c200> { URL: http://125.71.232.126:9090/FileManager/vr/assemblyJsonToHosueInfo } { status code: 500, headers {

Connection = close;
"Content-Language" = en;
"Content-Length" = 5900;
"Content-Type" = "text/html;charset=utf-8";
Date = "Fri, 25 Mar 2016 02:33:49 GMT";
Server = "Apache-Coyote/1.1";

} }

求大神解答

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

Antworte allen(3)
左手右手慢动作
mgr.requestSerializer = [AFJSONRequestSerializer serializer];
requestSerializer 修改 : forHTTPHeaderField:@"Content-Type"
   POST 前面加入:
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
阿神

关键点是"Request failed: unacceptable content-type: text/html",所以需要设置响应支持内容类型。

manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

好像是这样的,随手写的,不一定记得这个API!

伊谢尔伦

问一下楼主问题,怎样解决的,遇到同样的问题

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage