You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Michael Südkamp <mi...@docware.de> on 2005/01/21 12:00:41 UTC
File upload with PUT method
Hi,
I have started using httpclient 3.0-beta1.
I would like to do a file upload using HTTP PUT. (this is an intranet
application so security should be OK).
This is my sample code:
HttpClient client = new HttpClient();
PutMethod put = new PutMethod("http://linux3/upload");
RequestEntity entity = new InputStreamRequestEntity(new
FileInputStream("d:\\temp\\foo.txt"));
put.setRequestEntity(entity);
client.getHttpConnectionManager().
getParams().setConnectionTimeout(5000);
int status = client.executeMethod(put);
if (status == HttpStatus.SC_OK) {
System.out.println("Upload complete, response=" +
put.getResponseBodyAsString());
} else {
System.err.println("Upload failed, response=" +
HttpStatus.getStatusText(status));
}
My tests with IIS 5 and Apache 1.3 are:
IIS returns "Method not allowed". I think I habe to enable PUT somewhere.
But where?
With Apache my console log is:
21.01.2005 11:09:40 org.apache.commons.httpclient.HttpMethodDirector
isRedirectNeeded
INFO: Redirect requested but followRedirects is disabled
Upload failed, response=Moved Permanently
I am not really sure if this is a server or client issue.
If anyone is able to help me with IIS and/or Apache I would be glad.
Thanks
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org