6.1.2.3.3. How to perform WebDAV requests using curl ?

Simple Requests

For simple request such as: GET, HEAD, MKCOL, COPY, MOVE, DELETE, CHECKIN, CHECKOUT, UNCHECKOUT, LOCK, UNLOCK, VERSIONCONTROL, OPTIONS

perform:

curl -i -u 'user:pass' -X 'METHOD_NAME' 'resource_url'

for example to create a folder named test perform:

curl -i -u 'root:exo' -X MKCOL 'http://localhost:8080/rest/jcr/repository/production/test

to PUT a test.txt file from your current folder to "test "folder on server perform:

curl -i -u 'root:exo' -X PUT 'http://localhost:8080/rest/jcr/repository/production/test/test.txt' -d @test.txt

Requests with XML body

For requests which contains xml body such as: ORDER, PROPFIND, PROPPATCH, REPORT, SEARCH

add -d 'xml_body text' or -d @body.xml

(body.xml must contain a valid xml request bidy.) to you curl-command:

curl -i -u 'user:pass'  -X 'METHOD_NAME' -H 'Headers' 'resource_url' -d 'xml_body text'

For example about finding all files containing "test" perform:

curl -i -u "root:exo" -X "SEARCH" "http://192.168.0.7:8080/rest/jcr/repository/production/" -d
"<?xml version='1.0' encoding='UTF-8' ?>
   <D:searchrequest xmlns:D='DAV:'>
      <D:sql>SELECT * FROM nt:base WHERE contains(*, 'text')</D:sql>
</D:searchrequest>"

If you need to add some headers to your request, use \-H key.

To have more information about methods parameters, you can find in HTTP Extensions for Distributed Authoring specification.

Copyright ©2012. All rights reserved. eXo Platform SAS