1. @RequestMapping(value = "/post",method = RequestMethod.POST)
  2. @ResponseBody
  3. String GPost(@RequestParam("img1") MultipartFile[] img1,@RequestParam("img2") MultipartFile[] img2) throws IOException {
  4.  
  5. byte[] bytes1 = img1[0].getBytes();
  6. byte[] bytes2 = img2[0].getBytes();
  7.  
  8. HttpEntity reqEntity = MultipartEntityBuilder.create()
  9. .addPart("img1", new ByteArrayBody(bytes1, "img1"))
  10. .addPart("img2", new ByteArrayBody(bytes2, "img2"))
  11. .build();
  12.  
  13. String result="0";
  14. CloseableHttpClient httpclient = HttpClients.createDefault();
  15. try {
  16. HttpPost httppost = new HttpPost("http://1.6.1.192:806/F/Comp");
  17.  
  18. httppost.setEntity(reqEntity);
  19.  
  20. System.out.println("executing request " + httppost.getRequestLine());
  21. CloseableHttpResponse response = httpclient.execute(httppost);
  22.  
  23. int code = response.getStatusLine().getStatusCode(); // 这个取HTTP状态码。
  24. if (code == 302) {
  25. result="302";
  26. }
  27.  
  28. try {
  29. System.out.println("----------------------------------------");
  30. System.out.println(response.getStatusLine());
  31. HttpEntity resEntity = response.getEntity();
  32. if (resEntity != null) {
  33. System.out.println("Response content length: " + resEntity.getContentLength());
  34. result = EntityUtils.toString(resEntity);
  35. }
  36. EntityUtils.consume(resEntity);
  37.  
  38. } finally {
  39. response.close();
  40. }
  41. } finally {
  42. httpclient.close();
  43. }
  44.  
  45. return result;
  46.  
  47. }
  48. }

  

spring post 图片的更多相关文章

  1. spring mvc 图片上传,图片压缩、跨域解决、 按天生成文件夹 ,删除,限制为图片代码等相关配置

    spring mvc 图片上传,跨域解决 按天生成文件夹 ,删除,限制为图片代码,等相关配置 fs.root=data/ #fs.root=/home/dev/fs/ #fs.root=D:/fs/ ...

  2. spring boot图片上传至远程服务器并返回新的图片路径

    界面上传图片时考虑到可能会有用户的图片名称一致,使用UUID来对图片名称进行重新生成. //UUIDUtils public class UUIDUtils { public static Strin ...

  3. 【记录】spring boot 图片上传与显示

    问题:spring boot 使用的是内嵌的tomcat, 文件上传指定目录时不知道文件上传到哪个地方,不知道访问路径. //部署到服务器的tomcat上时通常使用这种方式request.getSer ...

  4. ckeditor+jsp+spring配置图片上传

    CKEditor用于富文本输入是极好的,它还有一些插件支持扩展功能,其中图片上传就是比较常用到的.本文简单记录我的实现步骤. 1.CKEditor除了提供三种标准版压缩包下载,还可根据自己的需求进行个 ...

  5. spring官网下载

    1.第一步:打开官网:http://projects.spring.io/ 2.第二步:点击“SPRING FRAMEWORK”图片 3.第三步:点击“小猫”图标 4.第四步:拉到页面中部的位置,找到 ...

  6. spring源码分析之spring-messaging模块详解

    0 概述 spring-messaging模块为集成messaging api和消息协议提供支持. 其代码结构为: 其中base定义了消息Message(MessageHeader和body).消息处 ...

  7. jsp使用${}语法,对应的spring后台使用Model

    实现的前提,一定要在jsp文件顶部加上 <%@page isELIgnored="false" %> 如上图${aa}与${bb},是直接使用Model的key值对应的 ...

  8. springboot 知识点

    ---恢复内容开始--- 1springBoot项目引入方式, 1,继承自父 project (需要没有付项目才能用,一般我们的项目都会有 父 项目 所以 这种方式不推荐 ,记住有这种方式 就可以了) ...

  9. 基于Rebound制造绚丽的动画效果-入门篇

    基于Rebound制造绚丽的动画效果-入门篇 Rebound是什么? Rebound是一个来自 Facebook 公司的 Java物理和动画库.Rebound spring 模型可用于创建动画,让你感 ...

随机推荐

  1. Java登陆拦截器

    package com.beidou.warehouseerp.interceptor; import com.alibaba.fastjson.JSON; import com.beidou.war ...

  2. JavaWeb快速入门

    孙卫琴老师的javaweb一书已经买了很多年,由于很厚一直也没有去好好阅读下, 项目发布后有闲暇时间,决定快速学习了,毕竟很多概念和知识主要还是复习. 对于互联网,我们可以简单认为浏览器就是会人类语言 ...

  3. ArduinoYun教程之OpenWrt-Yun与CLI配置Arduino Yun

    ArduinoYun教程之OpenWrt-Yun与CLI配置Arduino Yun OpenWrt-Yun OpenWrt-Yun是基于OpenWrt的一个Linux发行版.有所耳闻的读者应该听说他是 ...

  4. hdu 5652 India and China Origins(二分+bfs || 并查集)BestCoder Round #77 (div.2)

    题意: 给一个n*m的矩阵作为地图,0为通路,1为阻碍.只能向上下左右四个方向走.每一年会在一个通路上长出一个阻碍,求第几年最上面一行与最下面一行会被隔开. 输入: 首行一个整数t,表示共有t组数据. ...

  5. bzoj 1171 并查集优化顺序枚举 | 线段树套单调队列

    详见vfleaking在discuss里的题解. 收获: 当我们要顺序枚举一个序列,并且跳过某些元素,那么我们可以用并查集将要跳过的元素合并到一起,这样当一长串元素需要跳过时,可以O(1)跳过. 暴力 ...

  6. bzoj 3285 离散对数解指数方程

    /************************************************************** Problem: 3285 User: idy002 Language: ...

  7. git 撤销本地修改

    git checkout file 例如:git checkout app/views/carts/_index_m.html.erb 可以先用 git status 查看差异 然后 git chec ...

  8. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  9. AspNetPager 控件使用

    使用方法: 1.添加对AspNetPager.dll的引用 2.在页面上拖放控件 3. <%@ Register assembly="AspNetPager" namespa ...

  10. DMA Stream/Channel Outputting via GPIOC[0..7]

    Ok, so quickly mashing up another example using a different TIM, DMA Stream/Channel for illustration ...