搜索

首页  >  问答  >  正文

ios - AFN Code=-1011 "Request failed: internal server error (500)

我的代码:

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";

} }

求大神解答

大家讲道理大家讲道理2771 天前1322

全部回复(3)我来回复

  • ringa_lee

    ringa_lee2017-04-17 17:49:32

    雷雷

    回复
    0
  • 阿神

    阿神2017-04-17 17:49:32

    关键点是"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!

    回复
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:49:32

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

    回复
    0
  • 取消回复