我正在通过安卓实现应用程序上传文件。我有一项服务:http://example.com:1001/UPLOAD/FileUpload.do。我想上传一个文件和两个这样的参数
0?事件=上传&类型=:1
:0服务器 [当前 http://example.com:1001/UPLOAD/FileUpload.do]
:1 {发票、签名}
:2 表格上的文件,名称:上传文件
当我复制和粘贴时: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);
但我不知道,为什么它不上传到服务器。怎么了???
<form>
说event_Upload
; 你刚刚event
.这有帮助吗?
另请参阅通过 HTTP 表单上传文件,通过 MultipartEntityBuilder,带有进度条