- 利用 apache httpmime.jar包
- maven配置如下
- <dependency>
-
- <groupId>org.apache.httpcomponents</groupId>
-
- <artifactId>httpmime</artifactId>
-
- <version>4.0.2</version>
-
- </dependency>
- public static void main(String[] args) throws ClientProtocolException,
- IOException {
- HttpClient httpclient = new DefaultHttpClient();
-
- HttpPost httppost = new HttpPost(
- "http://localhost:8080/webtools/upload.jsp");
-
- FileBody file = new FileBody(new File("d:/22.rar"));
-
-
- MultipartEntity reqEntity = new MultipartEntity();
- reqEntity.addPart("fileField", file);
-
-
- httppost.setEntity(reqEntity);
-
- HttpResponse response = httpclient.execute(httppost);
- if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){
- HttpEntity entity = response.getEntity();
-
- }
- }