I try to get multiple event in caldav using a multiget request as explain here: http://sabre.io/dav/building-a-caldav-client
or here: Reading Apple/iCloud calendar data using PHP/CalDAV
It's suppose to be as simple as passing:
<?xml version="1.0" encoding="UTF-8"?>
<B:calendar-multiget xmlns:B="urn:ietf:params:xml:ns:caldav">
<A:prop xmlns:A="DAV:">
<B:calendar-data/>
</A:prop>
<A:href xmlns:A="DAV:">/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/00ECD3D1-72D0-4F56-9011-71A6180F848C.ics</A:href>
</B:calendar-multiget>
I'm using PHP to pass the XML request. But the XML response don't have any calendar-data:
SimpleXMLElement Object
(
[response] => SimpleXMLElement Object
(
[href] => /calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/00ECD3D1-72D0-4F56-9011-71A6180F848C.ics
[propstat] => SimpleXMLElement Object
(
[prop] => SimpleXMLElement Object
(
[calendar-data] => SimpleXMLElement Object
(
)
)
[status] => HTTP/1.1 200 OK
)
)
)
I use simplexml_load_string and print_r to display the result. How can I get the calendar-data?
GET method work fine but is too slow when I wan't to update >50 events.
EDIT: I can make it work using Curl in Terminal as suggested by hnh. But it doesn't work using curl in php. Here is the code I use (url element, log, pass, xml request are the same as the one use in terminal):
$xml= '<C:calendar-multiget xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"><prop><C:calendar-data/></prop><href>/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/94DA9025-02E5-4313-BF81-66641BC5989F.ics</href><href>/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/175CA348-8877-4CDF-B19D-4C66E191F4B4.ics</href></C:calendar-multiget>';
$user = "MyLogin";
$pw= "MyPsw";
$url = "https://localhost:443/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/";
$data = doRequest($user, $pw, $url, $xml);
print "<pre>";
print_r($data);
print "</pre>";
function doRequest($user, $pw, $url, $xml)
{
$c=curl_init($url);
curl_setopt($c, CURLOPT_HTTPHEADER, array("Depth: 1", "Content-Type: text/xml; charset='UTF-8'", "User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"));
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($c, CURLOPT_USERPWD, $user.":".$pw);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "REPORT");
curl_setopt($c, CURLOPT_POSTFIELDS, $xml);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($c);
curl_close($c);
return $data;
}
It doesn't return any calendar data:
/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/175CA348-8877-4CDF-B19D-4C66E191F4B4.ics
HTTP/1.1 200 OK
/calendars/__uids__/DE6BFE56-B3DC-4C60-A9C7-ED05A45AAC92/calendar/94DA9025-02E5-4313-BF81-66641BC5989F.ics
HTTP/1.1 200 OK