您好,登錄后才能下訂單哦!
代碼過程,把做工程過程經(jīng)常用到的一些代碼片段備份一下,下面的代碼是關(guān)于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;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。