[英]java- apache http client-query regarding submission of files as part of a multi part post request
我正在嘗試使用最新的Apache HTTP客戶端(v4.x)發送多部分POST請求-文檔提供的示例代碼提供了以下代碼示例(經過了部分修改)以發出POST請求-
FileBody bin = new FileBody(new File(args[0]));
StringBody comment = new StringBody("A binary file of some kind");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", bin);
reqEntity.addPart("comment", comment);
httppost.setEntity(reqEntity);
我感到困惑的是,如果要添加多個文件,則在代碼中
reqEntity.addPart("bin", bin);
第一個字符串代表什么? 是作為多部分過帳的一部分發送的文件的名稱嗎?
多部分表單請求可以包含多個部分,每個部分都有一個名稱(類似於常規表單請求)。 給定名稱,該名稱可在服務器端用於檢索特定部分。 RFC 2388中提供了詳細信息:
3. Definition of multipart/form-data The media-type multipart/form-data follows the rules of all multipart MIME data streams as outlined in [RFC 2046]. In forms, there are a series of fields to be supplied by the user who fills out the form. Each field has a name. Within a given form, the names are unique. "multipart/form-data" contains a series of parts. Each part is expected to contain a content-disposition header [RFC 2183] where the disposition type is "form-data", and where the disposition contains an (additional) parameter of "name", where the value of that parameter is the original field name in the form. For example, a part might contain a header: Content-Disposition: form-data; name="user"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.