[英]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.