我正在创建将文件发送到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
关于java - 如何在Java中使用Apache HttpComponents发送多部分/表单数据后请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18733562/