我想通过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错误请求,这是错误的:
Domain = com.alamofire.error.serialization.response Code = -1011“请求 失败:错误请求(400)“ UserInfo = {com.alamofire.serialization.response.error.response = {URL:http://121.42.203.122:8080/8minutes/uploadImg} {状态代码:400,headers { 连接=关闭; “Content-Language”= en; “内容长度”= 1105; “Content-Type”=“text / html; charset = utf-8”; 日期=“星期五,2015年12月11日05:36:46 GMT”; Server =“Apache-Coyote / 1.1”; }}
这是webservice url key:
param:{"file"}
我哪里错了?
答案 0 :(得分:3)
因为你得到的回答是“ text / html ”格式,所以它应该是 application / json 格式。
答案 1 :(得分:0)
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
试试这个......为我工作......