zoukankan      html  css  js  c++  java
  • spring post 图片

    @RequestMapping(value = "/post",method = RequestMethod.POST)
        @ResponseBody
         String GPost(@RequestParam("img1") MultipartFile[] img1,@RequestParam("img2") MultipartFile[] img2) throws IOException {
        	
        	byte[] bytes1 = img1[0].getBytes(); 
        	byte[] bytes2 = img2[0].getBytes(); 
        	
        	 HttpEntity reqEntity = MultipartEntityBuilder.create()
             		.addPart("img1", new ByteArrayBody(bytes1, "img1"))
             		.addPart("img2", new ByteArrayBody(bytes2, "img2"))
             		.build();
        	
        	 String result="0";
        	 CloseableHttpClient httpclient = HttpClients.createDefault();
             try {
                 HttpPost httppost = new HttpPost("http://1.6.1.192:806/F/Comp");
    
                 httppost.setEntity(reqEntity);
    
                 System.out.println("executing request " + httppost.getRequestLine());
                 CloseableHttpResponse response = httpclient.execute(httppost);
                 
                 int code = response.getStatusLine().getStatusCode(); // 这个取HTTP状态码。
                 if (code == 302) {
                	 result="302";
                 }
                 
                 
                 try {
                     System.out.println("----------------------------------------");
                     System.out.println(response.getStatusLine());
                     HttpEntity resEntity = response.getEntity();
                     if (resEntity != null) {
                         System.out.println("Response content length: " + resEntity.getContentLength());
                         result = EntityUtils.toString(resEntity);
                     }
                     EntityUtils.consume(resEntity);
                    
                 } finally {
                     response.close();
                 }
             } finally {
                 httpclient.close();
             }
             
            return result; 
        	
        	
        	
        	
        	
         }
    }
    

      

  • 相关阅读:
    [C#]获取指定文件文件名、后缀、所在目录等
    Mysql 存储引擎中InnoDB与Myisam的主要区别
    MySQL的btree索引和hash索引的区别
    Mysql事务的隔离级别
    AE序列号
    mysql索引类型说明
    去除url中自带的jsessionid
    redirect传值非url(springmvc3)
    ueditor的使用
    mysql用户管理(开户、权限)
  • 原文地址:https://www.cnblogs.com/ahuo/p/7506086.html
Copyright © 2011-2022 走看看