溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS通過http post上傳圖片的代碼

發(fā)布時(shí)間:2020-07-31 18:39:51 來源:網(wǎng)絡(luò) 閱讀:697 作者:peony324 欄目:移動(dòng)開發(fā)

代碼過程,把做工程過程經(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; 

}

向AI問一下細(xì)節(jié)

免責(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)容。

AI