ASIFormDataRequest *request=[ASIFormDataRequestrequestWithURL:[NSURL URLWithString:urlstr]];
//分界线的标识符
NSString*TWITTERFON_FORM_BOUNDARY = @"AaB03x";
//分界线--AaB03x
NSString*MPboundary=[[NSString alloc]initWithFormat:@"
--%@",TWITTERFON_FORM_BOUNDARY];
//结束符AaB03x--
NSString*endMPboundary=[[NSString alloc]initWithFormat:@"
%@--",MPboundary];
//声明结束符:--AaB03x--
NSString*end=[[NSString alloc]initWithFormat:@"
rn%@",endMPboundary];
//声明myRequestData,用来放入http body
NSMutableData *myRequestData=[NSMutableData data];
NSMutableString *body=[[NSMutableString alloc]init];
//将body字符串转化为UTF8格式的二进制
[myRequestData appendData:[bodydataUsingEncoding:NSUTF8StringEncoding]];
//将image的data加入
UIImage*image = [UIImage imageNamed:@"1212312.png"];
NSData *imageData = UIImagePNGRepresentation
(image);
[requestsetData:imageData withFileName:@"1122.png"andContentType:@"image/png" forKey:@"photo"];
[requestsetPostValue:string forKey:@"note"];//额外的文字参数
//加入结束符--AaB03x--
[myRequestData appendData:[enddataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"myRequestData =
%@",myRequestData);
//设置HTTPHeader中Content-Type的值
NSString*content=[[NSString alloc]initWithFormat:@"multipart/form-data;
boundary=%@",TWITTERFON_FORM_BOUNDARY];
[requestaddRequestHeader:@"Content-Type" value:content];
[requestaddRequestHeader:@"Content-Length" value:[NSStringstringWithFormat:@"%d", [myRequestData length]]];
[requestsetPostBody:myRequestData];
[requestsetRequestMethod:@"POST"];
[requeststartAsynchronous];
苹果客户端上传图片java接收
最新推荐文章于 2021-02-12 15:27:02 发布
本文介绍如何使用ASIFormDataRequest实现图片及文字参数的POST请求。通过设置分界线、内容类型、请求头等,实现了将图片数据和文本数据封装为multipart/form-data格式并发送到服务器。
摘要由CSDN通过智能技术生成