search

Home  >  Q&A  >  body text

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 days ago1324

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 17:49:32

    mgr.requestSerializer = [AFJSONRequestSerializer serializer];
    requestSerializer 修改 : forHTTPHeaderField:@"Content-Type"
       POST 前面加入:
        mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    

    reply
    0
  • 阿神

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

    The key point is "Request failed: unacceptable content-type: text/html", so you need to set the response support content type.

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

    It seems like this, I wrote it casually, I may not remember this API!

    reply
    0
  • 伊谢尔伦

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

    Ask the poster and how he solved it. I encountered the same problem

    reply
    0
  • Cancelreply