苹果客户端上传图片 java接收
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:[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:[body dataUsingEncoding:NSUTF8StringEncoding]];
//将image的data加入
UIImage *image = [UIImage imageNamed:@"1212312.png"];
NSData * imageData = UIImagePNGRepresentation(image);
[request setData:imageData withFileName:@"1122.png" andContentType:@"image/png" forKey:@"photo"];
[request setPostValue:string forKey:@"note"];//额外的文字参数
//加入结束符--AaB03x--
[myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"myRequestData = %@",myRequestData);
//设置HTTPHeader中Content-Type的值
NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
[request addRequestHeader:@"Content-Type" value:content];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", [myRequestData length]]];
[request setPostBody:myRequestData];
[request setRequestMethod:@"POST"];
[request startAsynchronous];
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。