[英]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.