问题描述
我正在尝试将本地数据库中的事件添加到Davical服务器中(实际上,只要它符合CalDav协议,它就应适用于任何CalDav服务器)...
I am trying to add an event from my local database to the Davical server (in fact, this should apply to any CalDav server, as long as it is compliant with the CalDav protocol)...
在中,我可以发送一个PUT请求以添加VCALENDAR集合中包含的事件...因此,我尝试这样做:
From what I could read here, I can send a PUT request to add events contained in a VCALENDAR collection... So here is what I try to do:
try {
// Create the HttpWebRequest object
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create("http://my_caldav_srv/davical.php/user/mycalendar");
// Add the network credentials to the request
Request.Credentials = new NetworkCredential(usr, pwd);
// Specify the method
Request.Method = "PUT";
// some headers - I MAY BE MISSING THINGS HERE???
Request.Headers.Add("Overwrite", "T");
// set the body of the request...
Request.ContentLength = bodyStr.Length;
Stream reqStream = Request.GetRequestStream();
// Write the string to the destination as a text file.
reqStream.Write( Encoding.UTF8.GetBytes(body), 0, body.Length);
// Set the content type header.
Request.ContentType = contentType.Trim();
// Send the method request and get the response from the server.
Response = (HttpWebResponse)Request.GetResponse();
}
catch (Exception e) {
throw new Exception("Caught error: " + e.Message, e);
}
我发送的邮件实际上是空日历:
The body I send is actually an emtpy calendar:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
PRODID:-//davical.org//NONSGML AWL Calendar//EN
X-WR-CALNAME:My Calendar
END:VCALENDAR
由于某种原因,我无法理解,带有 PUT的调用返回错误(405)不允许的方法。 PUSH返回(500)内部服务器错误,但查看调试详细信息,其原因与PUT情况相同...
For a reason I cannot understand, the call with "PUT" returns an error (405) Method Not Allowed. The PUSH returns (500) Internal Server Error, but looking at the debug details, the reason is the same as for the PUT case...
在服务器上进行调试方面,我发现原因是在 caldav-PUT-vcalendar.php 中,违反了以下条款:
In debugging on the server side, I found out that the reason is that in caldav-PUT-vcalendar.php, the following clause is violated:
$c->readonly_webdav_collections
首先,我要说的是在Lightning中输入相同的凭据,我就能添加/删除事件,并且在管理界面上,我实际上确保向用户授予所有权限。因此,我很惊讶是由于...
Well, first, let me mention that with the SAME credentials entered in Lightning, I am able to add/remove events and, on the admin interface, I actually made sure to grant ALL rights to the user. So I'd be surprised it is due to that...
任何帮助将不胜感激!
亲切的问候,
Nik
Any help would be most appreciated !Kind regards,Nik
推荐答案
好的,我明白了....
OK, I got it....
原因是必须将事件发布到某些事件地址...。
The reason is that one must put the event to some EVENT adress....
Ie url不是集合的地址,而是事件的地址...
I.e. the "url" is not the collection's address, but the EVENT's address...
因此使用以下地址的相同代码有效:
So the same code using the following address works:
string url="http://my_server/caldav.php/username/calendarpath/_my_event_id.ics";
有人知道是否可以一次插入/删除多个事件吗?
Does anybody know if it is possible to insert / delete multiple events at once ???
这篇关于使用Http请求和DDay.iCal将事件添加到Davical服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!