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

      

  • 相关阅读:
    (转)Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)
    (转)[疯狂Java]NIO:Channel的map映射
    AVL 树
    二叉查找树
    IE双击打不开解决办法
    CentOS安装mysql、JDK、Tomcat部署环境
    Tomcat安装与配置
    LoadRunner监控Centos和Ubuntu资源之服务器配置
    Fiddler
    Windows server 2008常用优化设置
  • 原文地址:https://www.cnblogs.com/ahuo/p/7506086.html
Copyright © 2011-2022 走看看