如何在 java 中的单个 HTTP 请求中发送对象和文件?

发布于 2024-10-20 07:52:58 字数 194 浏览 2 评论 0原文

我需要在单个 HTTP 请求中通过 HTTP 发送一个 java 对象和一个文件。我面临以下问题:

我正在使用 org.apache.commons.httpclient.HttpClient 实现,问题是服务器端的 servlet 需要请求中提到的多部分请求,因此我以字节形式发送的对象[] 流已损坏。如果我只是在单个请求中选择文件或对象,那么这工作正常。

I need to send a java object and a file via HTTP in a single HTTP request. I am facing following issue:

I am using org.apache.commons.httpclient.HttpClient implementation for this and the problem is the servlet on the server side expects the multipart request as mentioned in the request and hence the Object which I send as a byte[] stream gets corrupted. If I just either file or object in a single request then this works fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文