简体   繁体   English

java-apache http客户端查询,涉及作为多部分发布请求的一部分提交文件

[英]java- apache http client-query regarding submission of files as part of a multi part post request

I am trying to use the latest Apache HTTP Client (v4.x) to send a multi part POST request- the example code provided with the docs gives the following code sample (somewhat modified) to make a 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);

What I am confused about is, if I have multiple files to be added, then in the code 我感到困惑的是,如果要添加多个文件,则在代码中

   reqEntity.addPart("bin", bin);

what does the first string represent? 第一个字符串代表什么? Is it the name of the file which is being sent as part of multi part post? 是作为多部分过帐的一部分发送的文件的名称吗?

Multipart Form requests can have several parts, and each part is given a name (similar to a regular form request). 多部分表单请求可以包含多个部分,每个部分都有一个名称(类似于常规表单请求)。 This name can be used on the server side to retrieve a specific part, given the name. 给定名称,该名称可在服务器端用于检索特定部分。 Good details are available in RFC 2388: 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.

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