You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Yannick PIERSON <pi...@gmail.com> on 2008/04/21 17:30:22 UTC

httpClient upload file

Hi,
I need some help in order to upload a file on a IIS remote server through
webdav.

My aim is to upload the file from "c:\\temp\\conf_250206.pdf" to "
http://computer_name/webdav_access/Docs/<http://computer_name/webdav_access/Docs/test_conf.pdf>
"

I started with this code but it doesn't work :
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(new
AuthScope("localhost", 80), new UsernamePasswordCredentials("admin",
"admin"));

HttpPost httppost = new
HttpPost("http://computer_name/webdav_access/Docs<http://computer_name/webdav_access/Docs/test_conf.pdf>
");

File file = new File("c:\\temp\\conf_250206.pdf");
InputStreamEntity reqEntity = new InputStreamEntity(new
FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true);

FileEntity entity = new FileEntity(file, "binary/octet-stream");
httppost.setEntity(reqEntity);

HttpResponse response = httpclient.execute(httppost);
...

Must I use a servlet. If yes, why ?

Thanks.
Regards.

Yannick