http://blog.csdn.net/linzhu0831/article/details/7469223
http://www.xuanyusong.com/archives/1493
版权声明:本文为博主原创文章,未经博主允许不得转载。
1.单张图片上传
name: 处为url提供的参数名
NSDictionary *dic =@{参数};
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManageralloc] init];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes =[NSSetsetWithObject:@"text/html"];
[managerPOST:url parameters:dicconstructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(image)name:@"Filedata"fileName:@"test.jpg"mimeType:@"image/jpg"];
}success:^(AFHTTPRequestOperation *operation,id responseObject) {
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
}];
2.多张图片上传
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:url parameters:url参数 constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
for (int i = 0; i<arrayImage.count; i++) {
UIImage *uploadImage = arrayImage[i];
[formData appendPartWithFileData:UIImagePNGRepresentation(uploadImage) name:[NSString stringWithFormat:@"参数%d",i+1] fileName:@"test.jpg" mimeType:@"image/jpg"];
}
} error:nil];
AFHTTPRequestOperation *opration = [[AFHTTPRequestOperation alloc]initWithRequest:request];
opration.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[opration setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}