Codigo de ejemplo para utilizar WebDav
Ejemplo 1
Ejemplo 2
Tutotial de Apache Http Integrando WebDav Server
hosting a webdav folder using tomcat 6
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.jackrabbit.webdav.client.methods.PutMethod;
...
// WebDAV URL:
final String baseUrl = ...;
// Source file to upload:
File f = ...;
try{
HttpClient client = new HttpClient();
Credentials creds = new UsernamePasswordCredentials("username", "password");
client.getState().setCredentials(AuthScope.ANY, creds);
PutMethod method = new PutMethod(baseUrl + "/" + f.getName());
RequestEntity requestEntity = new InputStreamRequestEntity(
new FileInputStream(f));
method.setRequestEntity(requestEntity);
client.executeMethod(method);
System.out.println(method.getStatusCode() + " " + method.getStatusText());
}
catch(HttpException ex){
// Handle Exception
}
catch(IOException ex){
// Handle Exception
lunes, 21 de marzo de 2011
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario