1

我正在尝试使用 PHP 和 cURL 在 Nextcloud 中创建一个日历事件。从命令行运行代码后,我从 Nextcloud 12 收到以下错误:

PUT is not allowed on non-files.

这是我按照本指南使用的完整代码

<?php
$url = 'https://cloud.org/remote.php/dav/calendars/mycalendars/activity/';
$headers = array('Content-Type: text/calendar', 'charset=utf-8');
$userpwd = 'gerald:123';
$description = 'new event description';
$summary = 'new event';
$tstart = gmdate("Ymd\THis\Z", strtotime("-2 days"));
$tend = gmdate("Ymd\THis\Z", strtotime("-2 days"));
$tstamp = gmdate("Ymd\THis\Z");
$uid = 'event-123';

$body = <<<__EOD
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:$tstamp
DTSTART:$tstart
DTEND:$tend
UID:$uid
DESCRIPTION:$description
LOCATION:Office
SUMMARY:$summary
END:VEVENT
END:VCALENDAR
__EOD;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
//curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

//Execute the request.
$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

这是否意味着 Nextcloud 中的 CalDAV 不支持 PUT?那么像 Thunderbird Lightning 这样的日历应用程序是如何在 Nextcloud 中创建事件的呢?

在 Nextcloud WebDAV 文档中,我找不到任何有关 CalDAV 实施的信息。

4

1 回答 1

3

如果您使用 HTTPPUT请求,其目的是替换您正在引用的 uri 中的资源。因此,您的示例 HTTP 请求告诉我您正在替换

https://cloud.org/remote.php/dav/calendars/mycalendars/activity

那是对的吗?可能不是!您可能希望在该集合中创建一个新的日历资源。因此,为您的资源选择一个尚不存在的新 url:

https://cloud.org/remote.php/dav/calendars/mycalendars/activity/foo-bar-baz.ics
于 2018-06-04T21:57:57.237 回答