简体   繁体   English

如何在Java中发送具有不同内容类型的mime多部分宁静请求

[英]How to send mime multipart restful request with different content types in java

I have a bunch of requests of type xml and/or base64 encoded image that I want to send it to client's server, they have their REST API. 我有一堆类型为xml和/或base64编码的图像的请求,我想将其发送到客户端的服务器,它们具有REST API。 There is also a need to combine multiple requests into one to efficiently utilize the bandwidth. 还需要将多个请求组合成一个请求以有效地利用带宽。 So I was thinking of using mime-multipart request. 所以我在考虑使用mime-multipart请求。 What library I can use in java to accomplish this. 我可以在Java中使用什么库来完成此任务。 I know how to send a regular httpRequest in java but I dont know how to send a multipart mime request? 我知道如何在Java中发送常规的httpRequest,但我不知道如何发送多部分的mime请求? ie how will I specify different content type for each of the body? 即我将如何为每个正文指定不同的内容类型? Would appreciate any pointers. 将不胜感激任何指针。

I want to send something like this 我想寄这样的东西

Content-type: multipart/form-data;boundary=main_boundary

--main_boundary
Content-type: text/xml
<?xml version='1.0'?>
<content>
Some content goes here
</content>

--main_boundary
Content-type: multipart/mixed;boundary=sub_boundary

--main_boundary
Content-type: text/plain; charset=utf-8

 {base64 encoded string that represents image}

--main_boundary--

Feel free to correct me if I am wrong in my understanding. 如果我理解错误,请随时纠正我。 This is the first time I am using mime. 这是我第一次使用mime。

The Apache HttpClient library can help you construct multipart requests for file uploads. Apache HttpClient库可以帮助您构造文件上传的多部分请求。

Have a look here . 在这里看看。 And here is a sample application . 这是一个示例应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:获取MIME多部分BodyPart的内容 - Java: get content of MIME multipart BodyPart 如何使用Java中的Httpunit发送Multipart请求 - How to send Multipart request with Httpunit in Java 如何分段发送Jersey但每个文件具有不同的内容类型 - How to send Jersey multipart but with a different content type for each file 如何在java中使用HttpURLConnection发送多部分POST请求? - How to send multipart POST request using HttpURLConnection in java? 如何将图片作为多部分POST请求的一部分发送 - Java HtmlUnit - How to send a picture as part of a multipart POST request - Java HtmlUnit 如何构造正确的MultipartEntity以在Java中发送多部分/相关请求? - How to construct correct MultipartEntity to send a multipart/related request in java? 如何使用 RestAssured 发送多部分请求? - How to send a multipart request with RestAssured? 如何在ajax中发送多部分请求? - how to send multipart request in ajax? 如何让RESTful java客户端在Openstack上发送GET / POST请求? - How to make RESTful java client to send GET/POST request on Openstack? 如何使用org.glassfish.jersey.media.multipart从Java发送内容和文件作为多部分表单数据? - How to send content and file as Multipart Form Data from Java using org.glassfish.jersey.media.multipart?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM