我的代码:
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";
} }
求大神解答
阿神2017-04-17 17:49:32
핵심은 "요청 실패: 허용할 수 없는 콘텐츠 유형: text/html"이므로 응답 지원 콘텐츠 유형을 설정해야 합니다.
으아아아이런거 같은데, 아무렇지도 않게 쓴거라 이 API가 기억나지 않을 수도 있어요!