我遇到这个问题2天,Android应用程序适用于这个后台界面,但我总是收到500错误。我的代码是这样的。
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager POST:urlString parameters:self.param.mj_keyValues success:^(NSURLSessionDataTask *task, id responseObject) {
....
} failure:^(NSURLSessionDataTask *task, NSError *error) {
....
}];
然后,程序进入故障块,我得到这样的NSError日志。
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fc26b49a080> { URL: https://training.duapp.com/record_data } { status code: 500, headers {
Server = openresty;
Content-Type = text/html;charset=utf-8;
Vary = Accept-Encoding;
Content-Language = en;
Date = Fri, 02 Sep 2016 03:55:00 GMT;
Content-Encoding = gzip;
Content-Length = 646;
Connection = keep-alive;
}
}, NSErrorFailingURLKey=https://training.duapp.com/record_data, com.alamofire.serialization.response.error.data=
然后我试图将NSDictionary中的参数修改为NSData或NSString,并用它更改requestSerializer,但都失败了,错误500.参数的格式没有错误,这是我的后台工友所遵循的。我可以得到你有什么帮助吗?我该怎么办?
答案 0 :(得分:2)
Code=-1011 "Request failed: internal server error (500)"
是服务器端问题。请与您的服务器团队核实,因为服务器正在向您的请求返回错误。
答案 1 :(得分:0)
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
[params setObject:@"214" forKey:@"id"];
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/api_url"];
NSString *path = @"Path";
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:path parameters:params success:^(NSURLSessionDataTask *task, id responseObject){
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
NSLog(@"Success: %@", json);
}failure:^(NSURLSessionDataTask *task, NSError *error){
NSLog(@"Failure: %@", error);
}];