locked
PCL - HttpMethod.PATCH doesn't exist RRS feed

  • Question

  • User265422 posted

    Hello,

    I'm using Microsoft.HttpClient library in a PCL project and i have a problem with the PATCH httpmethod. She doesn't exist! How i can fix it?

    Best regards.

    Tuesday, November 29, 2016 2:46 PM

Answers

  • User265422 posted

    I fix my problem like this:

                    using (HttpClientHandler ClientHandler = new HttpClientHandler())
                    using (HttpClient Client = new HttpClient(ClientHandler))
                    {
                        Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", API.UserConnection.access_token);
                        using (HttpRequestMessage RequestMessage = new HttpRequestMessage(new HttpMethod("PATCH"), request))
                        {
                            RequestMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");
                            using (HttpResponseMessage ResponseMessage = await Client.SendAsync(RequestMessage))
                            {
                                string result = await ResponseMessage.Content.ReadAsStringAsync();
    
                                if (ResponseMessage.StatusCode == HttpStatusCode.NoContent)
                                {
                                    return true;
                                }
                                else
                                {
                                    await Error.Send(ResponseMessage.StatusCode, request, result);
                                    return false;
                                }
                            }
                        }
                    }
    

    I do not know how HttpMethod works behind, but I find this solution strange!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, November 29, 2016 4:09 PM