繁体   English   中英

如何在Java中使用Apache HttpComponents发送多部分/表单数据发布请求

[英]how to sending multipart/form-data Post Request in with use of Apache HttpComponents in java

我正在创建将文件发送到tomcat服务器的桌面应用程序。 Servlet接收器并保存文件。

我需要一些帮助来做一个在https站点中发布的Java程序。 我不知道如何放置参数,因为它是多部分表单数据连接类型。请帮助! 当我在Firefox上发表文章时

这将取决于。 在提供一系列表单键/名称对的基础上,我之前使用以下技术将多部分文件上传到服务器。

这将取决于您自己的要求以及servlet实际期望的内容。

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

String name = file.getName();

entity.addPart(new FormBodyPart("someFormParameter", new StringBody("someFormName")));
/*...*/
entity.addPart("formFileNameParameter", new FileBody(file, mimeType));

HttpClient client = /*...*/

HttpPost post = new HttpPost(url.toURI());
post.setEntity(entity);
HttpResponse response = client.execute(post);

// Process response

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM