我尝试使用 multiget 请求在 caldav 中获取多个事件,如下所述:http: //sabre.io/dav/building-a-caldav-client
或在这里: 使用 PHP/CalDAV 读取 Apple/iCloud 日历数据
它应该像传递一样简单:
<?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>
我正在使用 PHP 来传递 XML 请求。但是 XML 响应没有任何日历数据:
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
)
)
)
我使用 simplexml_load_string 和 print_r 来显示结果。如何获取日历数据?
GET 方法工作正常,但是当我不想更新 >50 个事件时太慢了。
编辑: 我可以按照 hnh 的建议在终端中使用 Curl 使其工作。但是在 php 中使用 curl 不起作用。这是我使用的代码(url 元素、日志、传递、xml 请求与终端中的使用相同):
$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;
}
它不返回任何日历数据:
/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