6

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?

2 Answers 2

10

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.