AFN 上传 纯文本和图片所调的函数区别

// 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.imageView.image, 1.0);
      [formData appendPartWithFileData:data name:@"pic" 
                  fileName:@"" mimeType:@"image/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:@"发送失败"];
      }];


你可能感兴趣的:(上传,AFN)