0

我正在尝试 Sardine 在 android 中制作 webdav 客户端,我正在尝试以下代码:

这在 JAVA 应用程序上完美运行,但在 android 中崩溃:(

    HttpClient client = new DefaultHttpClient();
    SardineImpl sardine = new SardineImpl((AbstractHttpClient) client,"testuser","test");
    List<DavResource> resources = sardine.getResources("http://demo.sabredav.org/");
    for (int i = 1; i < resources.size(); i++) {  

          System.out.println(resources.get(i));  
}

替换System.out.printlnToast我得到这个

11-24 16:05:34.602: ERROR/AndroidRuntime(19362): java.lang.NoSuchMethodError: org.apache.http.impl.client.AbstractHttpClient.setRedirectStrategy
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at com.googlecode.sardine.impl.SardineImpl.init(SardineImpl.java:188)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at com.googlecode.sardine.impl.SardineImpl.<init>(SardineImpl.java:182)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at es.sardine.sardine.onCreate(sardine.java:39)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.os.Looper.loop(Looper.java:143)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at android.app.ActivityThread.main(ActivityThread.java:4914)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at java.lang.reflect.Method.invoke(Method.java:521)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-24 16:05:34.602: ERROR/AndroidRuntime(19362):     at dalvik.system.NativeStart.main(Native Method)
4

3 回答 3

1

我在尝试使用 Sardine 并包含 Apache HttpClient 时遇到了同样的麻烦,这会与 Android 中嵌入的版本冲突。所以我决定用 OkHttp 代替它,我的麻烦少了很多。这是我创建的叉子:https ://github.com/thegrizzlylabs/sardine-android

于 2017-12-06T11:10:54.677 回答
0

你看到这个 q: Using webdav on Android 了吗?它本质上是说 Sardine 需要比 Android 软件包更新的 HttpClient 版本,并提供了一个链接到 Android 应用程序的修补 HttpClient 4.1。

于 2011-12-25T01:07:23.567 回答
0

对于您仅遍历服务器上的元素,此代码对我有用:

 try{

            Sardine sardine = SardineFactory.begin("username", "password");

            List<DavResource> resources = sardine.list("webdav/server/directory/");
            buffer = new StringBuilder();
            for (DavResource res : resources)
            {
                //for example
                buffer.append(res.toString());
            }
        }catch(Exception e){
                Log.e("VIEWER" , e.getMessage());
        }

我将Sardine-Android项目库与 simpleframework.xml 结合使用。

于 2015-10-18T17:40:50.037 回答