2
我執行的應用程序上傳文件有一個服務:http://example.com:1001/UPLOAD/FileUpload.do。我想上傳一個文件和兩個參數一樣,MultipartEntity POST的Android
0事件=上傳&類型=:1
:0 SERVER [當前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>
這是我的代碼的Android:
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);
但我不知道,爲什麼它不上傳到服務器。怎麼了???
我已經通過event_Upload替換事件,但它不工作,可怕的是對我來說:( – lonelyboy0212