DreamSea

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1. 利用 apache  httpmime.jar包
  2.         maven配置如下
  3. <dependency>
  4.             
  5. <groupId>org.apache.httpcomponents</groupId>
  6.            
  7.  <artifactId>httpmime</artifactId>
  8.             
  9. <version>4.0.2</version>
  10.       
  11. </dependency>
  12. public static void main(String[] args) throws ClientProtocolException,  
  13.             IOException {  
  14.         HttpClient httpclient = new DefaultHttpClient();  
  15.         //请求处理页面  
  16.         HttpPost httppost = new HttpPost(  
  17.                 "http://localhost:8080/webtools/upload.jsp");  
  18.         //创建待处理的文件  
  19.         FileBody file = new FileBody(new File("d:/22.rar"));  

  20.   
  21.         //对请求的表单域进行填充  
  22.         MultipartEntity reqEntity = new MultipartEntity();  
  23.         reqEntity.addPart("fileField", file);  
  24.    
  25.         //设置请求  
  26.         httppost.setEntity(reqEntity);  
  27.         //执行  
  28.         HttpResponse response = httpclient.execute(httppost);  

  29.         if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){  
  30.             HttpEntity entity = response.getEntity();  
  31.             
  32.         }  
  33.     }  
posted on 2011-07-28 14:54  DreamSea  阅读(823)  评论(0编辑  收藏  举报