您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
代码过程,把做工程过程经常用到的一些代码片段备份一下,下面的代码是关于iOS通过http post上传图片的代码,希望对大伙有些用处。
form = [[[ASIFormDataRequest alloc]
initWithURL:[NSURL URLWithString:url]] autorelease];
[form setTimeOutSeconds:60.0];
form.delegate = self;
imageView.image=[UIImage imageNamed:@"btn_done_down@2x.png"];
NSLog(@"%@",data);
for(int i=0;i<[keys count];i++)
{
if(![key isEqualToString:@"files"])
{
[body appendFormat:@"%@rn",MPboundary];
[body appendFormat:@"Content-Disposition: form-data; name="%@"rnrn",key];
[body appendFormat:@"%@rn",[sugestDic objectForKey:key]];
}
}
if (imageView.image) {
[body appendFormat:@"%@rn",MPboundary];
[body appendFormat:@"Content-Disposition: form-data; name="files"; filename="boris.png"rn"];
[body appendFormat:@"Content-Type: image/pngrnrn"];
}
[myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
[myRequestData appendData:data];
[myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
[form addRequestHeader:@"Content-Type" value:content];
[form addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", [myRequestData length]]];
[form setRequestMethod:@"POST"];
[form startAsynchronous];
[form setDidFailSelector:@selector(requestBeFailed:)];
[form setDidFinishSelector:@selector(requestBeFinished:)];
return tempDic;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。