c# - How Do You Correctly Write an XML Request for CALDAV Client .NET - Stack Overflow

I'm trying to access the events of an Apple Calendar. So far I was able to call PROPFIND and get t

I'm trying to access the events of an Apple Calendar. So far I was able to call PROPFIND and get the Principal User. Now my question is how do I use the principal user to find the server? I have the xml request. I just want to know how to add the Principal User to the request header?

I followed thislink

This is how they say to get the server link:

PROPFIND /200385701/principal/ HTTP/1.1
Host: caldav.icloud
Content-Type: application/xml; charset=utf-8
Authorization: Basic basicValue

<d:propfind xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="/">
  <d:prop>
    <cal:calendar-home-set/>
    <d:group-membership/>
  </d:prop>
</d:propfind>

This is my XML request string:

string xmlRequest2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:propfind xmlns:d=\"DAV:\" xmlns:cal=\"urn:ietf:params:xml:ns:caldav\" xmlns:cs=\"/\"><d:prop><cal:calendar-home-set/><d:group-membership/></d:prop></d:propfind>";

This is the method that I pass it into:

private string GetPrincipalServer(string username, string password, string calendarURI, string xmlRequest, string principalName)
{
    string principalServer = null;
    Stream ResponseStream;
    XmlDocument XmlDocument;
    WebHeaderCollection whc = new WebHeaderCollection();
    whc.Add(@"Translate", "F");

    ResponseStream = ExectueMethod(username, password, calendarURI, "PROPFIND", whc, xmlRequest, "text/xml");

    XmlDocument = new XmlDocument();
    XmlDocument.Load(ResponseStream);
    string xmlInner = XmlDocument.InnerXml;

    XmlDocument innerXmlDocument = new XmlDocument();
    innerXmlDocument.LoadXml(xmlInner);

    XmlNodeList lst = innerXmlDocument.GetElementsByTagName("href");
    principalServer = lst[lst.Count - 1].InnerText;
    ResponseStream.Close();
    return principalServer;
}

I think my code gets me part of the way there. I just don't know how to feed in the principal user which would actually give me the result that I need. In this example it is /200385701/principal/. So my question is how do I pass that into the header of my xml request?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745062807a4609070.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信