httpURLConnection.setRequestProperty("Content-type", "multipart/form-data; boundary=---------------------------7d318fd100112");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
DataOutputStream out = new DataOutputStream(httpURLConnection.getOutputStream());
out.writeBytes("-----------------------------7d318fd100112/r/n");
for(KeyValue v:post){
if(v.isFile()){
try{
out.writeBytes("content-disposition: form-data; name=/""+v.getKey()+"/"; filename=/""+v.getValue()+"/"/r/n");
out.writeBytes("content-type: application/octet-stream/r/n");
FileInputStream fis = new FileInputStream(v.getValue());
byte[] buffer = new byte[1024];
while(true){
synchronized(buffer){
int amountRead = fis.read(buffer);
if(amountRead==-1){
break;
}
out.write(buffer,0,amountRead);
}
}
fis.close();
}catch(IOException e){
log.error(e.getMessage());
}
}else{
out.writeBytes("content-disposition: form-data; name=/"" + v.getKey()+ "/"/r/n/r/n");
out.writeBytes(v.getValue());
}
out.writeBytes("/r/n-----------------------------7d318fd100112/r/n");
}
out.flush();
out.close();
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Cache-Control", "no-cache");
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
DataOutputStream out = new DataOutputStream(httpURLConnection.getOutputStream());
out.writeBytes("-----------------------------7d318fd100112/r/n");
for(KeyValue v:post){
if(v.isFile()){
try{
out.writeBytes("content-disposition: form-data; name=/""+v.getKey()+"/"; filename=/""+v.getValue()+"/"/r/n");
out.writeBytes("content-type: application/octet-stream/r/n");
FileInputStream fis = new FileInputStream(v.getValue());
byte[] buffer = new byte[1024];
while(true){
synchronized(buffer){
int amountRead = fis.read(buffer);
if(amountRead==-1){
break;
}
out.write(buffer,0,amountRead);
}
}
fis.close();
}catch(IOException e){
log.error(e.getMessage());
}
}else{
out.writeBytes("content-disposition: form-data; name=/"" + v.getKey()+ "/"/r/n/r/n");
out.writeBytes(v.getValue());
}
out.writeBytes("/r/n-----------------------------7d318fd100112/r/n");
}
out.flush();
out.close();