如何在 java 中的单个 HTTP 请求中发送对象和文件?
我需要在单个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过本教程:http://evgenyg。 wordpress.com/2010/05/01/uploading-files-multipart-post-apache/ ?
Have you tried this tutorial: http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/ ?