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; 
        	
        	
        	
        	
        	
         }
    }
    

      

  • 相关阅读:
    浏览器HTTP缓存原理分析
    基本概念复习
    什么是IOC为什么要使用IOC
    AutoFac记录
    NHibernate之旅(21):探索对象状态
    如何获取类或属性的自定义特性(Attribute)
    a different object with the same identifier value was already associated with the session
    6 CLR实例构造器
    6 CLR静态构造器
    CLR via C# 提纲
  • 原文地址:https://www.cnblogs.com/ahuo/p/7506086.html
Copyright © 2011-2022 走看看