1

I have to do a patch request using the HTTP Client in C#.Seems very simple to do a Get request:

        var httpclient = GetHttpClient(accessToken.Result);
        var response = await 
        httpclient.GetAsync("https://graph.microsoft.com/v1.0/me/messages");
        response.EnsureSuccessStatusCode();
        var content = await response.Content.ReadAsStringAsync();
        JObject o = JObject.Parse(content);

However for a patch, I cannot find a PatchAsync method, only seems to have POST and PUT.

0

1 Answer 1

1

Replace GetAsync with this in your code

var httpclient = GetHttpClient(accessToken.Result);
var response = await client.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), "https://graph.microsoft.com/v1.0/me/messages"));
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
JObject o = JObject.Parse(content);
Sign up to request clarification or add additional context in comments.

5 Comments

Where would the httpcontent go?
@user8608110 please Check Edited answer.
Surely the content should go in the response variable ?
@MihirDave conde-only answers that don't explain what the code does or why it solves the problem are not considered good answers. This code is actually wrong - you forgot to add the content for the PATCH verb. Besides, adding yet another answer when there are good duplicates adds noise and makes it harder for the next person to find an answer
@user8608110 yes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.