我正在通过android实现应用程序上传文件。我有一个服务:http ://example.com:1001/UPLOAD/FileUpload.do 。我想上传一个文件和两个这样的参数
0?事件=上传&类型=:1
:0 服务器 [当前 http://example.com:1001/UPLOAD/FileUpload.do]
:1 {发票,签名}
:2 表格上的文件,名称为:UploadedFile
当我在浏览器上复制和粘贴:http ://example.com:1001/UPLOAD/FileUpload.do然后它会响应这样的表单
<head></head>
<body>
<form enctype="multipart/form-data" action="FileUpload.do" method="post">
<input type="file" name="UploadedFile"></input>
<input type="hidden" value="invoice" name="type"></input>
<input type="submit" value="Upload" name="event_Upload"></input>
</form>
</body>
这是我的代码安卓:
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://example.com:1001/UPLOAD/FileUpload.do");
File file = new File(pathFile);
FileBody fileBody = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("event", new StringBody("Upload"));
reqEntity.addPart("type", new StringBody("invoice"));
reqEntity.addPart("UploadedFile", fileBody);
httpPost.setEntity(reqEntity);
httpClient.execute(httpPost);
但我不知道,为什么它不上传到服务器。怎么了???