iOS通过http post上传图片的代码
代码过程,把做工程过程经常用到的一些代码片段备份一下,下面的代码是关于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;
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。