5

我有一个 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

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

4

1 回答 1

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);
于 2011-05-20T03:13:16.820 回答