依赖.

        <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<!-- <version>4.5.3</version> -->
</dependency>
import java.io.File;
import java.io.IOException; import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; public class TestMultiPartUpload { /**
* TODO 方法说明。
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try { HttpPost post = new HttpPost("http://127.0.0.1:8080/mypath/test"); post.setHeader("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;)");
post.setHeader("charset", "utf-8");
String token = "4dc6098e-d584-4883-a4e7-45adc5xxxxxx";
post.setHeader("Authorization", "Bearer " + token);
post.setHeader("Accept", "application/json");
// post.setHeader("Content-Type", "multipart/mixed;boundary=----QWERTYUIO");
FileBody img1 = new FileBody(new File("D:/img/1.jpg"), ContentType.create("image/jpeg"), "1.jpg");
FileBody img2 = new FileBody(new File("D:/img/4.jpg"), ContentType.create("image/jpeg"), "4.jpg"); StringBody meta = new StringBody("{ \"key1\":\"v1\"; \"key2\":\"v2\" }", ContentType.APPLICATION_JSON); HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("files", img1)
.addPart("files", img2)
//.addPart("story", meta).setBoundary("----QWERTYUIO")
.addPart("story", meta)
.build(); post.setEntity(reqEntity); CloseableHttpResponse response = httpClient.execute(post);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
System.out.println("Response content: " + InputStreamUtil.toString(resEntity.getContent()));
System.out.println("Response content length: " + resEntity.getContentLength());
}
EntityUtils.consume(resEntity);
} finally {
response.close();
} } finally {
httpClient.close();
} } }

http post multipart/mixed的文件.的更多相关文章

  1. Java 处理 multipart/mixed 请求

    一.multipart/mixed 请求   multipart/mixed 和 multipart/form-date 都是多文件上传的格式.区别在于,multipart/form-data 是一种 ...

  2. 使用JavaMail发送邮件-no object DCH for MIME type multipart/mixed报错解决

    最近需要实现一个使用Spring schedule按一定时间间隔自动触发条件发送邮件的功能,在开发的过程中,是按照先测试能发出text/html文本邮件,然后测试添加附件发送邮件,我碰到的问题是,文本 ...

  3. Multipart/form-data POST文件上传详解

    Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form ...

  4. Multipart/form-data POST文件上传详解(转)

    Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form ...

  5. 构建multipart/form-data实现文件上传

    构建multipart/form-data实现文件上传 通常文件上传都是通过form表单中的file控件,并将form中的content-type设置为multipart/form-data.现在我们 ...

  6. Http请求之基于HttpUrlConnection,支持Header,Body传值,支持Multipart上传文件:

    Http请求之基于HttpUrlConnection,支持Header,Body传值,支持Multipart上传文件: public static String post(String actionU ...

  7. 发送邮件报错javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed

    关于使用javaMail发送邮件报错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multip ...

  8. request doesn't contain a multipart/form-data or multipart/mixed stream ……

    有文件控件"file"的表单,在提交的时候,直接使用了ajax提交,结果报了一堆错,原来这个东东要提交表单,还要用post方式,最后更改为: $("#saveForm&q ...

  9. spring mvc利用MultipartResolver解析Multipart/form-data进行文件上传

    之前的表单数据都是文本数据,现记录:利用MultipartResolver进行文件上传. ①首先,需引入commons-fileUpload和commons-io jar包,pom.xml文件的坐标: ...

随机推荐

  1. ILP32、ILP64、LP64、LLP64、64位系统

    Data Type     ILP32      ILP64     LP64      LLP64char              8             8            8     ...

  2. 【RS】CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Collaborative Filtering-CoupledCF:在推荐系统深度协作过滤中学习显式和隐式的用户物品耦合

    [论文标题]CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Colla ...

  3. 【LeetCode】207. Course Schedule (2 solutions)

    Course Schedule There are a total of n courses you have to take, labeled from 0 to n - 1. Some cours ...

  4. Elasticstack 5.1.2 集群日志系统部署及实践

    Elasticstack 5.1.2 集群日志系统部署及实践 一.ELK Stack简介 ELK Stack 是Elasticsearch.Logstash.Kibana三个开源软件的组合,在实时数据 ...

  5. android image加载中等待动画

    在布局中添加一个ImageViw和一个EditText. <ImageView android:id="@+id/loading_imageView_info" androi ...

  6. 【jquery】$(document).ready() 与window.onload的区别

    Jquery中$(document).ready()的作用类似于传统JavaScript中的window.onload方法,不过与window.onload方法还是有区别的. 1)执行时间  wind ...

  7. HTML自定义对象与属性探究(谷歌,火狐,IE9浏览器没问题)

    1.自定义标签 <zqz>asdas</zqz> <style> zqz{ color:red; } </style> 页面变色 2.自定义标签的hov ...

  8. fdatool的滤波器设计

    作者:桂. 时间:2017-08-15  20:28:11 链接:http://www.cnblogs.com/xingshansi/p/7367738.html 前言 本文主要记录滤波器设计的基本流 ...

  9. 微信小程序图片宽100%显示并且不变形

    <view class="meiti" style="background-color:red;"> <image src="htt ...

  10. [置顶] app后端设计--总目录

    版权声明:本文为博主原创文章,未经博主允许不得转载. 做了3年app相关的系统架构,api设计,先后在3个创业公司中工作,经历过手机网页端,Android客户端,iphone客户端,现就职于app云后 ...