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