WebDAV xml callback using PHP - sabre/dav

61 views Asked by At

While building a carddav client in PHP I am not able to get back a xml response like in the documentation. Request from docu - https://sabre.io/dav/building-a-carddav-client/:

PROPFIND /addressbooks/johndoe/contacts/ HTTP/1.1
Depth: 0
Content-Type: application/xml; charset=utf-8

<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
  <d:prop>
     <d:displayname />
     <cs:getctag />
  </d:prop>
</d:propfind>`

Expected Response:

<d:multistatus xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
    <d:response>
        <d:href>/addressbooks/johndoe/contacts/</d:href>
        <d:propstat>
            <d:prop>
                <d:displayname>My Address Book</d:displayname>
                <cs:getctag>3145</cs:getctag>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>
</d:multistatus>

my PHP looks like this:

use Sabre\DAV\Client;
include 'vendor/autoload.php';

$settings = array(
   'baseUri' => 'http://localhost/baikal/html/dav.php/',
   'userName' => 'testuser',
   'password' => 'testpwd',
   'proxy' => '',
);
        
$client = new Client($settings);

$addressbook = '/default/';
$user = 'testuser';
$addressbookURI = './addressbooks/' . $user . $addressbook;

$body = '
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
  <d:prop>
     <cs:getctag />
  </d:prop>
</d:propfind>
            
';
        
$response = $client->request('PROPFIND', $addressbookURI, $body, array('Depth' => '0', 'Content-Type' => 'application/xml; charset=utf-8'));

var_dump($response);

This request brings exact the information I expected but not as xml which I can parse in some way. Response: ["body"]=> string(426) " /baikal/html/dav.php/addressbooks/testuser/default/8HTTP/1.1 200 OK " in this example 8 would be the variable I need, is there a way to get back a xml or an array as shown in the documentation? I tried different carddav servers and different requests, every time the same issue.

0

There are 0 answers