Adding events to Davical server using Http request and DDay.iCal

点点圈 提交于 2019-12-25 16:20:52

问题


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)...

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

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...

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

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...

Any help would be most appreciated ! Kind regards, Nik


回答1:


OK, I got it....

The reason is that one must put the event to some EVENT adress....

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 ???



来源:https://stackoverflow.com/questions/27609122/adding-events-to-davical-server-using-http-request-and-dday-ical

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!