// 1.创建请求管理对象
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
AFN上传中,如有图片数据需要用些API ,如下例子, 用UIImageJPEGRepresentation将图片转成二进制,再传送。
[mgr POST:@"https://upload.api.weibo.com/2/statuses/upload.json"
parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSData *data = UIImageJPEGRepresentation(self.p_w_picpathView.p_w_picpath, 1.0);
[formData appendPartWithFileData:data name:@"pic"
fileName:@"" mimeType:@"p_w_picpath/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
[MBProgressHUD showSuccess:@"发送成功"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[MBProgressHUD showError:@"发送失败"];
}];
普通的上传,则用以下API即可、
[mgr POST:@"https://api.weibo.com/2/statuses/update.json"
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
[MBProgressHUD showSuccess:@"发送成功"];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[MBProgressHUD showError:@"发送失败"];
}];
转载于:https://blog.51cto.com/whistle/1560903