MultipartEntity POST机器人 [英] MultipartEntity POST android
问题描述
我被android.I实现应用程序上传文件有一个服务:的http://例子.COM:1001 /上载/ FileUpload.do 。我想上传一个文件和两个参数一样,
I'm implementing app upload file by android.I have a service : http://example.com:1001/UPLOAD/FileUpload.do. I want to upload a file and two parameter like that
事件=上传和放大器;类型= 1
0?event=Upload&type=:1
:0服务器[当前http://example.com:1001/UPLOAD/FileUpload.do]
:0 SERVER [current http://example.com:1001/UPLOAD/FileUpload.do]
:1 {发票,签字}
:1 {invoice, signature}
:2文件的形式与名称:UploadedFile的
:2 File on form with name: UploadedFile
当我复制和粘贴: http://example.com:1001/UPLOAD/FileUpload。做在浏览器上,它响应这样的形式
When I copy and paste : http://example.com:1001/UPLOAD/FileUpload.do on browser then it response a form like that
<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>
这是我的code机器人:
This is my code 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);
但我不知道,为什么不上传到服务器。什么是错的???
But I don't know , why it doesn't upload to server . What's wrong???
推荐答案
在&LT;形式GT;
表示, event_Upload
;你刚才事件
。这是否帮助?
The <form>
says event_Upload
; you have just event
. Does that help?
另请参见<一个href="http://stackoverflow.com/questions/18964288/upload-a-file-through-an-http-form-via-multipartentitybuilder-with-a-progress">Upload通过HTTP格式的文件,通过MultipartEntityBuilder,进度条
这篇关于MultipartEntity POST机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!