import java.io.File;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
public class MultiFileUpload {
/**
* @param args
* @throws IOException
* @throws ClientProtocolException
*/
public static void main(String[] args) throws ClientProtocolException, IOException {
// TODO Auto-generated method stub
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://210.10.3.98:8080/trademall/uploadPhoto/upload.do");
FileBody fileBody1 = new FileBody(new File(
"./imgs/1.jpg"));
FileBody fileBody2 = new FileBody(new File(
"./imgs/2.jpg"));
MultipartEntity entity = new MultipartEntity();
entity.addPart("files", fileBody1);
entity.addPart("files", fileBody2);
post.setEntity(entity);
HttpResponse response = httpclient.execute(post);
}
}
给出下载链接: