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接收
2019-02-21 17:30:02
浏览数 (1)