AFHTTPRequestOperationManager *�manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer= [AFHTTPResponseSerializer serializer];
[manager POST:url parameters:params constructingBodyWithBlock:^(id formData) {
NSData *data =UIImageJPEGRepresentation(image,0.5);//把要上传的图片转成NSData
//把要上传的文件转成NSData
//NSString*path=[[NSBundlemainBundle]pathForResource:@"123"ofType:@"txt"];
//NSData*fileData = [NSDatadataWithContentsOfFile:path];
[formData appendPartWithFileData:dataname:@"uploadFile" fileName:@"图片1" mimeType:@"image/png"];//给定数据流的数据名,文件名,文件类型(以图片为例)
/*常用数据流类型:
@"image/png" 图片
@“video/quicktime” 视频流
*/
}success:^(AFHTTPRequestOperation*operation,id responseObject) {
//NSLog(@"%@",responseObject);//返回结果
}failure:^(AFHTTPRequestOperation*operation,NSError*error) {
//NSLog(@"%@",error.localizedDescription);//请求失败结果
}];
网友评论