AFNetworking返回400错误请求



我想通过AFNetworking发布图像,这是代码

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
[manager POST:URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
     [formData appendPartWithFileData:UIImageJPEGRepresentation(selfPhoto, 1) name:@"file" fileName:imageFilePath mimeType:@"image/jpg"];
 }

但是返回400个错误的请求,这里是errro:

域=com.alamofire.error.serialization.response代码=-1011"请求失败:错误的请求(400)"UserInfo={com.alamofire.serialization.response.error.response={URL:http://121.42.203.122:8080/8minutes/uploadImg}{状态代码:400,标头{连接=关闭;"内容语言"=en;"内容长度"=1105;"内容类型"="text.html;charset=utf-8";日期="2015年12月11日星期五格林尼治标准时间05:36:46";服务器="Apache Coyote/1.1";}}

这是Web服务url密钥:

  param:{"file"}

我哪里错了?

因为您得到的响应是"text/html/strong>"格式,所以它应该是application/json格式。

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];

试试这个。。。为我工作。。。

相关内容

最新更新