【发布时间】:2015-07-01 14:03:22
【问题描述】:
我正在使用 Apache 的 HttpPost。我正在尝试将文件上传到网络服务器,结果如下:
POST 站点/上传?uploadType=chunked&requestId={requestId} HTTP/1.1
主持人:
接受:应用程序/xml
授权令牌:
请求参数
requestId 当前上传会话的唯一标识符。
请求标头
Host Web 服务器的主机名。
接受 响应的格式。有效值为:application/xml 或 application/json。
Authtoken 登录成功后收到的认证令牌。
FileEOF 指定当前文件块是否已到达文件末尾。允许的值为 0 和 1。文件结尾表示值 1。
请求正文
以字节为单位包含文件块的内容。
我想出的是这样的:
HttpPost post = new HttpPost(url);
post.setHeader("Authtoken", params.get("token"));
String fileName = file.getName();
long offset = Long.parseLong(chunkOffset);
//...
post.setHeader("FileEOF", eof);
/*List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("requestId", requestId));
post.setEntity(new UrlEncodedFormEntity(postParameters));*/
fileInputStream.skip(offset);
fileInputStream.read(bytes);
post.setEntity(new ByteArrayEntity(bytes));
HttpPost 的参数在哪里写呢?
【问题讨论】:
标签: java http-post apache-httpcomponents