我正在尝试将一些压缩数据和文本发布到 Web 服务器上的 perl 程序,但无法将标头从八位字节流更改为多部分/表单数据。
我的代码是:-
HttpClient httpclient = new DefaultHttpClient();
String url = "http://webaddress/perl.pl";
HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-Type","multipart/form-data");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
try {
entity.addPart("mtdata",new ByteArrayBody(data, file.getLastPathSegment()));
entity.addPart("email", new StringBody(strUserName));
entity.addPart("mtfilename", new StringBody(file.getLastPathSegment()));
httppost.setEntity(entity);
HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
response = EntityUtils.toString(resEntity);
}
收到的原始数据是:-
Buffer = --FfT4ZNRUCPw6yONkpSsXNkA3WA2l6fvy53
Content-Disposition: form-data; name="mtdata"; filename="filename"
Content-Type: application/octet-stream <<=== cannot change this
... Some binary data ...
我究竟做错了什么?