开发者

how to upload file using http put in android?

开发者 https://www.devze.com 2023-03-07 16:44 出处:网络
I have a REST web service and android. Now I want to request Http Put using android to call web service. In my REST web serviceif user want to do Http Put he can request in terminal like t开发者_JAVA技

I have a REST web service and android. Now I want to request Http Put using android to call web service. In my REST web service if user want to do Http Put he can request in terminal like t开发者_JAVA技巧his :

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

My question is how to set -T /home/student1/a.jpg in android using HttpPut?


Here is some snippet you can use:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消