我正在尝试使用 AFHTTPSessionManager 上传多个文件(图像),但请求失败,代码=-1011“请求失败:内部服务器错误(500)”。
这是我的代码。
NSString *urlString = [BaseUrl stringByAppendingString:UploadImages];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
NSString *apiKey = [[Utility sharedInstance] getObjectForKey:API_KEY];
[manager.requestSerializer setValue:apiKey forHTTPHeaderField:@"Authorization"];
[manager POST:urlString parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
for(int i = 0 ;i < pictures.count; i++){
UIImage *image = [pictures objectAtIndex:i];
NSData * imageData = UIImageJPEGRepresentation(image, 0.5);
[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"file%d",i] fileName:[NSString stringWithFormat:@"file%d.jpg",i] mimeType:@"image/jpeg"];
}
}progress:nil success:^(NSURLSessionTask *task, id responseObject){
NSLog(@"Pictures Uploaded");
}failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Uploading failed %@",[error localizedDescription]);
}];
失败:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x14803b080> { URL: https://BaseUrl/v1/imgupload } { status code: 500, headers {
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "Thu, 16 Jun 2016 09:25:43 GMT";
Server = "Apache/2.4.7 (Ubuntu)";
"X-Powered-By" = "PHP/5.5.9-1ubuntu4.14";
} }, NSErrorFailingURLKey=https://BaseUrl/v1/imgupload, com.alamofire.serialization.response.error.data=<>, NSLocalizedDescription=Request failed: internal server error (500)}
如果我做错了什么,请告诉我。谢谢