Вопрос

I'm using the HttpClient and I need to set a non-standard type for the HttpMethod. Where using HttpWebRequest only expects a string, HttpClient expects an HttpMethod. Enumerating the available values in HttpMethod, I don't see a way to add a custom one. Any thoughts?

Это было полезно?

Решение

Don't know why I didn't think of trying this before, but I can call new HttpMethod("MYMETHOD");

Другие советы

Thank you so much. I tried the weirdest stuff, but i did not see this simple solution :)

I try to use CalDAV REST-Requests to connect with my ownCloud-CalDAV-Server within a XAML-C#-MetroApp. Works perfect now. I finally can change the HTTP-Method to the PROPFIND-Type.

Here my Code for retrieving Infos ( http://sabre.io/dav/building-a-caldav-client/ ).

    ...
        try {
            HttpClientHandler httpClientHandler = new HttpClientHandler();
            httpClientHandler.AllowAutoRedirect = false;
            httpClientHandler.Credentials = new NetworkCredential(caldavuserTB.Text, caldavpasswordTB.Text);

            HttpClient httpClient = new HttpClient(httpClientHandler);
            httpClient.MaxResponseContentBufferSize = 256000;

            propfindMethod = new HttpMethod("PROPFIND");

            propfindHttpRequestMessage = new HttpRequestMessage(propfindMethod, webURLAsURI);

            propfindHttpRequestMessage.Headers.Add("Prefer", "return-minimal");
            propfindHttpRequestMessage.Headers.Add("Depth", "0");
            propfindHttpRequestMessage.Headers.Add("Accept", "application/xml; charset=utf-8");
            propfindHttpRequestMessage.Content = new StringContent("<d:propfind xmlns:d=\"DAV:\" xmlns:cs=\"http://calendarserver.org/ns/\"><d:prop><d:displayname /><cs:getctag /></d:prop></d:propfind>");


            propfindHttpResponseMesage = await httpClient.SendAsync(propfindHttpRequestMessage);
        }
    ...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top