1

I am trying to create a new calendar in my principal's home folder using SabreDav.

I couldn't find how to achieve this - is it even possible ?

UPDATE: I found out about MKCALENDAR method, but the following returns an "abandoned" request error:

<C:mkcalendar xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav"  xmlns:ical="http://apple.com/ns/ical/" >"
    <D:set>
        <D:prop>
            <D:displayname>cal Display Name</D:displayname> 
            <ical:calendar-color>cal Color</ical:calendar-color>
        </D:prop>
    </D:set>
</C:mkcalendar>

Sending it with a HttpWebRequest fails with a canceled request messgage...

Thanks in advance!

UPDATE 2: Some more details:

HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create("http://my.sabredavcalendar.srv/calendarserver.php/calendars/admin/my_new_calendar/");
Request.Method = "MKCALENDAR";
Request..Credentials = new NetworkCredentials("usr", "pwd");
Request.ContentType = "application/xml";
string body = "<C:mkcalendar [.....]  </C:mkcalendar>";
Request.ContentLength = body.Length;
// ---
// The using block throws an error...
using (Stream reqStream = Request.GetRequestStream()) {
    byte[] encodedBody = Encoding.UTF8.GetBytes(body);
    reqStream.Write(encodedBody, 0, encodedBody.Length);
    reqStream.Close();
}
Response = (HttpWebResponse)Request.GetResponse();

The error message I get is

The request was aborted: The request was canceled

On the server side, here is the access log:

192.168.1.200 - - [06/Jul/2015:09:51:48 +0200] "MKCALENDAR /calendarserver.php/calendars/admin/my_new_calendar/ HTTP/1.1" 400 25 "-" "-"

The error log is empty... so it seems I get a "bad request" response which is not caught when preparing the request?!

UPDATE 3: the body contains special characters as "éàê..." which is why the contentlength part was wrong !

neggenbe
  • 1,697
  • 2
  • 24
  • 62
  • 1
    You are providing too little information. What is the URL you are sending this to? What is the HTTP error returned by the server? P.S.: The 'modern' way to create calendars is via MKCOL, though all servers should support MKCALENDAR as well. – hnh Jul 05 '15 at 10:49
  • I added as many details as I could - please see UPDATE 2 – neggenbe Jul 06 '15 at 08:02
  • 2
    You need to figure out a way to enable more logging in your server to figure out why it is throwing a 400. You omitted your body variable, so maybe something is wrong in there. P.S.: Request.ContentLength = body.Length is wrong, you need to set the content-length to the UTF8 byte length, though it shouldn't matter in your sample. – hnh Jul 06 '15 at 08:10

1 Answers1

1

I take hnh's comment as an answer: the problem was indeed the Request.ContentLength = body.Length.

Corrected code is:

Request.ContentLength = Encoding.UTF8.GetByteCount(body);
neggenbe
  • 1,697
  • 2
  • 24
  • 62