【问题标题】:How to send mime multipart restful request with different content types in java如何在java中发送具有不同内容类型的mime multipart restful请求
【发布时间】:2012-06-01 06:52:18
【问题描述】:

我有一堆 xml 和/或 base64 编码图像类型的请求,我想将其发送到客户端的服务器,它们有自己的 REST API。还需要将多个请求合并为一个以有效利用带宽。所以我在考虑使用 mime-multipart 请求。我可以在java中使用什么库来完成这个。我知道如何在 java 中发送常规 httpRequest 但我不知道如何发送多部分 mime 请求?即我将如何为每个正文指定不同的内容类型?不胜感激。

我想发送这样的东西

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

如果我的理解有误,请随时纠正我。这是我第一次使用 mime。

【问题讨论】:

    标签: java rest mime multipart


    【解决方案1】:

    Apache HttpClient 库可以帮助您构建文件上传的多部分请求。

    看看here。这是sample application

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 2021-12-04
      • 1970-01-01
      • 2017-02-05
      • 2011-03-29
      • 2013-08-08
      相关资源
      最近更新 更多