iOS用三方ASIHttpRequest上传图片

1.新建一个single view工程,导入ASIHttpRequest库,导入MobileCoreServices,SystemConfiguration和libz1.2.5.dylib

2.随便导入一张图片

3.在VC中

NSURL* url = [NSURL URLWithString:@"..."];//请求的url

UIImage* img = [UIImage imageNamed:@"XXX.png"];

NSData* data = UIImagePNGRepresentation(img);

//请求是post请求

ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL:url];

//请求的代理 签代理

request.delegate = self;

[request setPostValue:self.m_auth forKey:@"m_auth"];

//    [request setFile:@"OOO.png" forKey:@"XXX"];

[request setData:data  withFileName:@"tmp.png"andContentType:@"image/png"forKey:@"headimage"];

[request startAsynchronous];

你可能感兴趣的:(iOS用三方ASIHttpRequest上传图片)