我的代码:
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";
} }
求大神解答
The key point is "Request failed: unacceptable content-type: text/html", so you need to set the response support content type.
It seems like this, I wrote it casually, I may not remember this API!
Ask the poster and how he solved it. I encountered the same problem