为了绕过 Box 文件/文件夹 ID 并支持许多其他服务,我决定使用 WebDAV 实现,因为我对我的 linux 机器上的它有点熟悉。我选择了一个基于 JackRabbit 的库,经过修改后可以在 Android 上运行,这似乎适合我的需求。然而,没过多久,我就遇到了问题。
当试图列出 Box 的根条目时,multiStatus.getResponses() 返回一个空数组。当访问另一个 webdav 服务器时,我得到了预期的响应。两台服务器都按预期返回状态代码 207。
我的代码在下面,有什么想法吗?
编辑:我可以移动文件,但列出目录的条目不起作用:/
String host = "https://www.box.com/dav/";
//String host = "http://demo.sabredav.org/";
hostConfig = new HostConfiguration();
hostConfig.setHost(host);
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
connectionManager.setParams(params);
client = new HttpClient(connectionManager);
Credentials creds = new UsernamePasswordCredentials("BOXEMAILADDRESS", "MYBOXPASSWORD");
//Credentials creds = new UsernamePasswordCredentials("testuser", "test");
client.getState().setCredentials(AuthScope.ANY, creds);
client.setHostConfiguration(hostConfig);
try
{
String propfindUri = host;
DavMethod method = new PropFindMethod(propfindUri, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
client.executeMethod(method);
Log.i("Status: " + method.getStatusCode());
MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
Log.i("Length: " + responses.length);
for(MultiStatusResponse response : responses)
{
Log.i("File: " + response.getHref());
}
}
catch (Exception e)
{
Log.printStackTrace(e);
}