Android学习记录(二十二)-Android WEBDAV MKCOL的使用

越鸿才
2023-12-01

先上需求:

使用webdav上行文件之前,需要创建目录。

坑在哪里:

http 4.0以后http不再支持excutemethod的方法。不能直接调用mkcol方法进行目录创建。

解决的办法:

查看开源库:

https://github.com/lookfirst/sardine的实现:

使用下面的代码自己创建mkcol的类。

static class HttpMkCol extends HttpEntityEnclosingRequestBase {
    public static final String METHOD_NAME = "MKCOL";

    public HttpMkCol(String url) {
        this(URI.create(url));
    }

    public HttpMkCol(URI url) {
        this.setURI(url);
    }

    @Override
    public String getMethod() {
        return METHOD_NAME;
    }
}

HttpMkCol mkCol = new HttpMkCol(sUrl);

try {
    HttpResponse response = httpClient.execute(mkCol, context);
 这样就解决了问题。 


个人参考了一下:

public class HttpPut extends HttpEntityEnclosingRequestBase {
    public static final String METHOD_NAME = "PUT";

    public HttpPut() {
        throw new RuntimeException("Stub!");
    }

    public HttpPut(URI uri) {
        throw new RuntimeException("Stub!");
    }

    public HttpPut(String uri) {
        throw new RuntimeException("Stub!");
    }

    public String getMethod() {
        throw new RuntimeException("Stub!");
    }
}
 



 类似资料: