如何使用http放入android上传文件?

sud*_*udo 5 rest android web-services httprequest http-put

我有一个REST Web服务和android.现在我想使用android来请求Http Put来调用Web服务.在我的REST Web服务中,如果用户想要做Http Put,他可以在终端中请求如下:

curl -H"Content-Type:application/vnd.org.snia.cdmi.dataobject"-v -T /home/student1/a.jpg http:// localhost:8080/user1/folder/a.jpg

我的问题是如何在Android中使用HttpPut设置-T /home/student1/a.jpg?

aro*_*ero 8

以下是您可以使用的一些代码段:

File f = new File(...);
...
...
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPut httpPut = new HttpPut("http://mydomain.com/some/action");

MultipartEntity entity = new MultipartEntity();
entity.addPart("myFile", new FileBody(f));

httpPut.setEntity(entity);
HttpResponse response  = httpclient.execute(httpPut);
Run Code Online (Sandbox Code Playgroud)