How do I make a WebDav call using HttpClient?

心已入冬 提交于 2019-12-11 07:30:18

问题


Specifically I want to call MKCOL through HttpClient to create a folder for Apache Jackrabbit through the Sling REST API.

I've tried variants of

BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("MKCOL", restUrl);

But no dice so far. I'm guessing this is less difficult than I'm making it.

I also see there is MkColMethod for something like

MkColMethod mkColMethod = new MkColMethod(restUrl);

But I don't know how to utilize this. I think it may have worked with a previous version of HttpClient. I'm using 4.x


回答1:


Best is to look at the Sling integration tests, which use Sling's RESTful APIs to create content.

The "old" SlingIntegrationTestClient class [1] is used to test Sling itself and uses httpclient 3.x to create content. It is used by the tests found at [2], so you can find examples there.

The "new" SlingClient class [3] is meant to be a cleaner and simpler re-implementation of that, used by the Sling testing tools described at http://sling.apache.org/site/sling-testing-tools.html . It uses httpclient 4.x which has a slightly different API.

The SlingClient.mkdir and mkdirs methods do use the MKCOL method.

[1] http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/SlingIntegrationTestClient.java

[2] http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests

[3] http://svn.apache.org/repos/asf/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java




回答2:


The best answer is to use Sardine. http://sardine.googlecode.com/

It is absurd to have to look at a bunch of unit tests to figure out who to use webdav.



来源:https://stackoverflow.com/questions/6023876/how-do-i-make-a-webdav-call-using-httpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!