从 CalDav 创建新日历 API

Create a new calendar from CalDav API

我正在尝试使用 SabreDav 在我校长的主文件夹中创建一个新日历。

我找不到如何实现这一点 - 有可能吗?

更新: 我发现了 MKCALENDAR 方法,但是以下 returns 一个 "abandoned" 请求错误:

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

使用 HttpWebRequest 发送失败,请求消息被取消...

提前致谢!

更新 2: 更多细节:

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 request was aborted: The request was canceled

在服务器端,这是访问日志:

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

错误日志是空的...所以我似乎收到了 "bad request" 准备请求时未捕获的响应?!

更新 3:正文包含“éàê...”等特殊字符,这就是内容长度部分错误的原因!

我把 hnh 的评论作为答案:问题确实是 Request.ContentLength = body.Length

更正后的代码是:

Request.ContentLength = Encoding.UTF8.GetByteCount(body);