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

      

  • 相关阅读:
    sftp上传到远程服务器
    mysql 的 find_in_set函数使用方法
    wamp2.5 局域网无法访问问题
    JS图片上传预览
    select2的相关问题
    linux 更新源miss问题
    freeMarker遍历map的正确方式
    Input类型是checkbox时checked属性获取
    Java 内存区域划分 备忘录
    简单聊聊java中如何判定一个对象可回收
  • 原文地址:https://www.cnblogs.com/ahuo/p/7506086.html
Copyright © 2011-2022 走看看