您好,登錄后才能下訂單哦!
代碼過程,把做工程過程經常用到的一些代碼片段備份一下,下面的代碼是關于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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。