使用AFNetworking的iOS POST:NSLocalizedDescription =请求失败:内部服务器错误(500)

时间:2014-07-24 00:48:17

标签: ios objective-c afnetworking afnetworking-2

我有一个UITextField,我想在UITextField中写一些内容时更新我的​​服务器 按更新按钮,我使用AFNetworking,但我有一个错误:

 Domain=com.alamofire.error.serialization.response Code=-1011 
 "Request failed: internal server error (500)
{ status code: 500, headers {
"Access-Control-Allow-Headers" = "Origin, X-Requested-With, Content-Type, Accept";
"Access-Control-Allow-Methods" = "OPTIONS,GET,POST,PUT,DELETE";
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Type" = "text/plain";
Date = "Thu, 24 Jul 2014 00:41:56 GMT";
Server = Cowboy;
"Transfer-Encoding" = Identity;
Via = "1.1 vegur";
"X-Powered-By" = Express;
} }, NSLocalizedDescription=Request failed: internal server error (500)}

这是我的更新按钮代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];


NSDictionary *params = @ {@"status" :_status};


[manager POST:BASE_URL parameters:params
      success:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"JSON: %@", responseObject);
 }
      failure:
 ^(AFHTTPRequestOperation *operation, NSError *error) {
     NSLog(@"Error: %@", error);
 }];

感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

错误代码,-1011表示kCFURLErrorBadServerResponse(来自docs)。您的网络服务(API)会为您提供AFNetworking的请求/响应序列化程序无法获知的响应。请您的开发团队查看并更正错误。

答案 1 :(得分:-2)

从代码中删除此行:

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

并将您的requestSerializer更改为:[AFHTTPRequestSerializer serializer];

这在我的应用程序中运行良好。