如果已设置具有摘要授权的SabreDAV CalDAV服务器。通过iPhone,Outlook / CalDavSychronizer,Thunderbird / Lightning访问日历时,一切正常!
现在我试图通过php使用php_curl访问日历:
<?php
$url = "http://servername/calendars/user/calendar1/";
$username = "username";
$password = "password";
$calStart = gmdate("Ymd\THis\Z");
$calEnd = gmdate("Ymd\THis\Z", strtotime("+4 weeks"));
$postdata = '<C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop xmlnx:D="DAV:">
<C:calendar-data>
<C:expand start="'.$calStart.'"
end="'.$calEnd.'"/>
</C:calendar-data>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="'.$calStart.'"
end="'.$calEnd.'"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'REPORT');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Depth: 1', 'Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($postdata)));
curl_setopt($curl, CURLOPT_USERPWD , $username.':'.$password);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$raw_response = curl_exec($curl);
curl_close($curl);
echo "raw response: " . $raw_response;
?>
但答案总是如此:
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:sabredav-version>3.2.2</s:sabredav-version>
<s:exception>ErrorException</s:exception>
<s:message>XMLReader::XML(): Empty string supplied as input</s:message>
</d:error>
Apache访问日志:
xxx.xxx.xxx.xxx - - [24/Apr/2017:21:21:43 +0200] "REPORT /calendars/user/calendar1/ HTTP/1.1" 500 275 "-" "-"
Apache错误日志:
[Mon Apr 24 21:44:16.824217 2017] [http:trace3] [pid 10895] http_filters.c(1087): [client yyy.yyy.yyy.yyy:60834] Response sent with status 500, headers:
[Mon Apr 24 21:44:16.824228 2017] [http:trace5] [pid 10895] http_filters.c(1094): [client yyy.yyy.yyy.yyy:60834] Date: Mon, 24 Apr 2017 19:44:16 GMT
[Mon Apr 24 21:44:16.824233 2017] [http:trace5] [pid 10895] http_filters.c(1097): [client yyy.yyy.yyy.yyy:60834] Server: Apache
[Mon Apr 24 21:44:16.824236 2017] [http:trace4] [pid 10895] http_filters.c(916): [client yyy.yyy.yyy.yyy:60834] X-Sabre-Version: 3.2.2
[Mon Apr 24 21:44:16.824239 2017] [http:trace4] [pid 10895] http_filters.c(916): [client yyy.yyy.yyy.yyy:60834] Content-Length: 275
[Mon Apr 24 21:44:16.824254 2017] [http:trace4] [pid 10895] http_filters.c(916): [client yyy.yyy.yyy.yyy:60834] Connection: close
[Mon Apr 24 21:44:16.824257 2017] [http:trace4] [pid 10895] http_filters.c(916): [client yyy.yyy.yyy.yyy:60834] Content-Type: application/xml; charset=utf-8
知道问题出在哪里?感谢...
2017/04/27修改:
我想我已经把问题缩小了一点点。它处理摘要授权。预期的行为是:
除了REPORT ...
之外,这适用于每个请求(GET,PROPFIND,...)记录包括 REPORT 请求:
[Thu Apr 27 20:53:08.964878 2017] Headers received from client:
[Thu Apr 27 20:53:08.964924 2017] Host: servername
[Thu Apr 27 20:53:08.964929 2017] Accept: */*
[Thu Apr 27 20:53:08.964933 2017] Depth: 1
[Thu Apr 27 20:53:08.964937 2017] Content-Type: text/xml; charset=utf-8
[Thu Apr 27 20:53:08.969111 2017] Response sent with status 500, headers:
[Thu Apr 27 20:53:08.969123 2017] Date: Thu, 27 Apr 2017 18:53:08 GMT
[Thu Apr 27 20:53:08.969126 2017] Server: Apache
[Thu Apr 27 20:53:08.969130 2017] X-Sabre-Version: 3.2.2
[Thu Apr 27 20:53:08.969133 2017] Content-Length: 275
[Thu Apr 27 20:53:08.969135 2017] Connection: close
[Thu Apr 27 20:53:08.969138 2017] Content-Type: application/xml; charset=utf-8
记录包括 PROPFIND 请求(最终400是正确的...如果已使用REPORT有效负载测试PROPFIND ......):
[Thu Apr 27 20:41:27.445149 2017] Headers received from client:
[Thu Apr 27 20:41:27.445177 2017] Host: servername
[Thu Apr 27 20:41:27.445180 2017] Accept: */*
[Thu Apr 27 20:41:27.445183 2017] Depth: 1
[Thu Apr 27 20:41:27.445186 2017] Content-Type: text/xml; charset=utf-8
[Thu Apr 27 20:41:27.451752 2017] Response sent with status 401, headers:
[Thu Apr 27 20:41:27.451763 2017] Date: Thu, 27 Apr 2017 18:41:27 GMT
[Thu Apr 27 20:41:27.451766 2017] Server: Apache
[Thu Apr 27 20:41:27.451769 2017] X-Sabre-Version: 3.2.2
[Thu Apr 27 20:41:27.451772 2017] Vary: Brief,Prefer
[Thu Apr 27 20:41:27.451775 2017] DAV: 1, 3, extended-mkcol, access-control, calendarserver-principal-property-search, calendar-access, calendar-proxy, calendarserver-subscribed, calendar-auto-schedule, calendar-availability, resource-sharing, calendarserver-sharing
[Thu Apr 27 20:41:27.451778 2017] WWW-Authenticate: Digest realm=\\"realm\\",qop=\\"auth\\",nonce=\\"59023b576e21c\\",opaque=\\"df58bdff8cf60599c939187d0b5c54de\\"
[Thu Apr 27 20:41:27.451781 2017] Content-Length: 432
[Thu Apr 27 20:41:27.451784 2017] Content-Type: application/xml; charset=utf-8
[Thu Apr 27 20:41:27.452122 2017] Headers received from client:
[Thu Apr 27 20:41:27.452129 2017] Authorization: Digest username=\\"username\\", realm=\\"realm\\", nonce=\\"59023b576e21c\\", uri=\\"/calendars/user/calendar1/\\", cnonce=\\"MGNmM2VlNzlkYzcwZDA2ZTMzOTk5N2VjMzI3MjA0NzI=\\", nc=00000001, qop=auth, response=\\"7715ae276bf6dceb656e555ab89ed72c\\", opaque=\\"df58bdff8cf60599c939187d0b5c54de\\"
[Thu Apr 27 20:41:27.452140 2017] Host: servername
[Thu Apr 27 20:41:27.452144 2017] Accept: */*
[Thu Apr 27 20:41:27.452146 2017] Depth: 1
[Thu Apr 27 20:41:27.452149 2017] Content-Type: text/xml; charset=utf-8
[Thu Apr 27 20:41:27.452152 2017] Content-Length: 380
[Thu Apr 27 20:41:27.454866 2017] Response sent with status 400, headers:
[Thu Apr 27 20:41:27.454876 2017] Date: Thu, 27 Apr 2017 18:41:27 GMT
[Thu Apr 27 20:41:27.454883 2017] Server: Apache
[Thu Apr 27 20:41:27.454886 2017] X-Sabre-Version: 3.2.2
[Thu Apr 27 20:41:27.454889 2017] Content-Length: 316
[Thu Apr 27 20:41:27.454892 2017] Connection: close
[Thu Apr 27 20:41:27.454894 2017] Content-Type: application/xml; charset=utf-8
[Thu Apr 27 20:37:41.739309 2017] Response sent with status 400, headers:
[Thu Apr 27 20:37:41.739321 2017] Date: Thu, 27 Apr 2017 18:37:41 GMT
[Thu Apr 27 20:37:41.739324 2017] Server: Apache
[Thu Apr 27 20:37:41.739328 2017] X-Sabre-Version: 3.2.2
[Thu Apr 27 20:37:41.739330 2017] Content-Length: 316
[Thu Apr 27 20:37:41.739333 2017] Connection: close
[Thu Apr 27 20:37:41.739336 2017] Content-Type: application/xml; charset=utf-8
对我来说这看起来像个错误。但是哪里?是卷曲还是SabreDAV?