How do I do a patch request using HttpClient in dotnet core? The Next CEO of Stack OverflowHow to use Backbone.js partial update (patch: true)?How many HttpClients should I create?Is a partial representation of document a valid “set of changes” as per HTTP PATCH RFC?How to use PATCH method in CXFHow to use PATCH method in CXF ClientAdd client certificate to .net core HttpclientHow should I use the HttpClient in an ASP.NET Core 2.0 APISalesforce Rest API patch operation - Bad RequestPosting HTTP request with C# HTTPClientHttpClient hangs with concurrent tasks

Free fall ellipse or parabola?

Is French Guiana a (hard) EU border?

Airplane gently rocking its wings during whole flight

Is there a reasonable and studied concept of reduction between regular languages?

Can I board the first leg of the flight without having final country's visa?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Strange use of "whether ... than ..." in official text

How can I make proper oatmeal cookies?

What CSS properties can the br tag have?

What flight has the highest ratio of timezone difference to flight time?

Won the lottery - how do I keep the money?

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

Why don't programming languages automatically manage the synchronous/asynchronous problem?

What difference does it make using sed with/without whitespaces?

Calculate the Mean mean of two numbers

Is it professional to write unrelated content in an almost-empty email?

Is there a difference between "Fahrstuhl" and "Aufzug"?

Why is information "lost" when it got into a black hole?

Asymptote: 3d graph over a disc

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

Can we install two versions of Java JDK in windows

Is a distribution that is normal, but highly skewed, considered Gaussian?

Inductor and Capacitor in Parallel

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?



How do I do a patch request using HttpClient in dotnet core?



The Next CEO of Stack OverflowHow to use Backbone.js partial update (patch: true)?How many HttpClients should I create?Is a partial representation of document a valid “set of changes” as per HTTP PATCH RFC?How to use PATCH method in CXFHow to use PATCH method in CXF ClientAdd client certificate to .net core HttpclientHow should I use the HttpClient in an ASP.NET Core 2.0 APISalesforce Rest API patch operation - Bad RequestPosting HTTP request with C# HTTPClientHttpClient hangs with concurrent tasks










7















I am trying to create a Patch request with theHttpClient in dotnet core. I have found the other methods,



using (var client = new HttpClient())

client.GetAsync("/posts");
client.PostAsync("/posts", ...);
client.PutAsync("/posts", ...);
client.DeleteAsync("/posts");



but can't seem to find the Patch option. Is it possible to do a Patch request with the HttpClient? If so, can someone show me an example how to do it?










share|improve this question

















  • 2





    use a HttpRequestMessage

    – Daniel A. White
    Oct 2 '16 at 12:08











  • Thanks @DanielA.White you got me on my way!

    – Tom Aalbers
    Oct 2 '16 at 13:37
















7















I am trying to create a Patch request with theHttpClient in dotnet core. I have found the other methods,



using (var client = new HttpClient())

client.GetAsync("/posts");
client.PostAsync("/posts", ...);
client.PutAsync("/posts", ...);
client.DeleteAsync("/posts");



but can't seem to find the Patch option. Is it possible to do a Patch request with the HttpClient? If so, can someone show me an example how to do it?










share|improve this question

















  • 2





    use a HttpRequestMessage

    – Daniel A. White
    Oct 2 '16 at 12:08











  • Thanks @DanielA.White you got me on my way!

    – Tom Aalbers
    Oct 2 '16 at 13:37














7












7








7








I am trying to create a Patch request with theHttpClient in dotnet core. I have found the other methods,



using (var client = new HttpClient())

client.GetAsync("/posts");
client.PostAsync("/posts", ...);
client.PutAsync("/posts", ...);
client.DeleteAsync("/posts");



but can't seem to find the Patch option. Is it possible to do a Patch request with the HttpClient? If so, can someone show me an example how to do it?










share|improve this question














I am trying to create a Patch request with theHttpClient in dotnet core. I have found the other methods,



using (var client = new HttpClient())

client.GetAsync("/posts");
client.PostAsync("/posts", ...);
client.PutAsync("/posts", ...);
client.DeleteAsync("/posts");



but can't seem to find the Patch option. Is it possible to do a Patch request with the HttpClient? If so, can someone show me an example how to do it?







dotnet-httpclient http-patch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 2 '16 at 12:07









Tom AalbersTom Aalbers

1,30721331




1,30721331







  • 2





    use a HttpRequestMessage

    – Daniel A. White
    Oct 2 '16 at 12:08











  • Thanks @DanielA.White you got me on my way!

    – Tom Aalbers
    Oct 2 '16 at 13:37













  • 2





    use a HttpRequestMessage

    – Daniel A. White
    Oct 2 '16 at 12:08











  • Thanks @DanielA.White you got me on my way!

    – Tom Aalbers
    Oct 2 '16 at 13:37








2




2





use a HttpRequestMessage

– Daniel A. White
Oct 2 '16 at 12:08





use a HttpRequestMessage

– Daniel A. White
Oct 2 '16 at 12:08













Thanks @DanielA.White you got me on my way!

– Tom Aalbers
Oct 2 '16 at 13:37






Thanks @DanielA.White you got me on my way!

– Tom Aalbers
Oct 2 '16 at 13:37













2 Answers
2






active

oldest

votes


















9














Thanks to Daniel A. White's comment, I got the following working.



using (var client = new HttpClient())

var request = new HttpRequestMessage(new HttpMethod("PATCH"), "your-api-endpoint");

try

response = await client.SendAsync(request);

catch (HttpRequestException ex)

// Failed







share|improve this answer


















  • 2





    where do you add the body?

    – DanielGatti
    Apr 10 '18 at 14:30











  • @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

    – DeadlyChambers
    Jul 30 '18 at 15:54












  • see my response on how to add body

    – iberodev
    Mar 8 at 17:27


















0














HttpClient does not have patch out of the box.
Simply do something like this:



// more things here
using (var client = new HttpClient())

client.BaseAddress = hostUri;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
var method = "PATCH";
var httpVerb = new HttpMethod(method);
var httpRequestMessage =
new HttpRequestMessage(httpVerb, path)

Content = stringContent
;
try

var response = await client.SendAsync(httpRequestMessage);
if (!response.IsSuccessStatusCode)

var responseCode = response.StatusCode;
var responseJson = await response.Content.ReadAsStringAsync();
throw new MyCustomException($"Unexpected http response responseCode: responseJson");


catch (Exception exception)

throw new MyCustomException($"Error patching stringContent in path", exception);







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39816829%2fhow-do-i-do-a-patch-request-using-httpclient-in-dotnet-core%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    Thanks to Daniel A. White's comment, I got the following working.



    using (var client = new HttpClient())

    var request = new HttpRequestMessage(new HttpMethod("PATCH"), "your-api-endpoint");

    try

    response = await client.SendAsync(request);

    catch (HttpRequestException ex)

    // Failed







    share|improve this answer


















    • 2





      where do you add the body?

      – DanielGatti
      Apr 10 '18 at 14:30











    • @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

      – DeadlyChambers
      Jul 30 '18 at 15:54












    • see my response on how to add body

      – iberodev
      Mar 8 at 17:27















    9














    Thanks to Daniel A. White's comment, I got the following working.



    using (var client = new HttpClient())

    var request = new HttpRequestMessage(new HttpMethod("PATCH"), "your-api-endpoint");

    try

    response = await client.SendAsync(request);

    catch (HttpRequestException ex)

    // Failed







    share|improve this answer


















    • 2





      where do you add the body?

      – DanielGatti
      Apr 10 '18 at 14:30











    • @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

      – DeadlyChambers
      Jul 30 '18 at 15:54












    • see my response on how to add body

      – iberodev
      Mar 8 at 17:27













    9












    9








    9







    Thanks to Daniel A. White's comment, I got the following working.



    using (var client = new HttpClient())

    var request = new HttpRequestMessage(new HttpMethod("PATCH"), "your-api-endpoint");

    try

    response = await client.SendAsync(request);

    catch (HttpRequestException ex)

    // Failed







    share|improve this answer













    Thanks to Daniel A. White's comment, I got the following working.



    using (var client = new HttpClient())

    var request = new HttpRequestMessage(new HttpMethod("PATCH"), "your-api-endpoint");

    try

    response = await client.SendAsync(request);

    catch (HttpRequestException ex)

    // Failed








    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 2 '16 at 13:37









    Tom AalbersTom Aalbers

    1,30721331




    1,30721331







    • 2





      where do you add the body?

      – DanielGatti
      Apr 10 '18 at 14:30











    • @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

      – DeadlyChambers
      Jul 30 '18 at 15:54












    • see my response on how to add body

      – iberodev
      Mar 8 at 17:27












    • 2





      where do you add the body?

      – DanielGatti
      Apr 10 '18 at 14:30











    • @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

      – DeadlyChambers
      Jul 30 '18 at 15:54












    • see my response on how to add body

      – iberodev
      Mar 8 at 17:27







    2




    2





    where do you add the body?

    – DanielGatti
    Apr 10 '18 at 14:30





    where do you add the body?

    – DanielGatti
    Apr 10 '18 at 14:30













    @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

    – DeadlyChambers
    Jul 30 '18 at 15:54






    @DanielGatti is right. What are you sending as the body for your PATCH? What I did was add it to the object. request.Content = new StringContent(jsonString, Encoding.UTF8, "applicantion/json");

    – DeadlyChambers
    Jul 30 '18 at 15:54














    see my response on how to add body

    – iberodev
    Mar 8 at 17:27





    see my response on how to add body

    – iberodev
    Mar 8 at 17:27













    0














    HttpClient does not have patch out of the box.
    Simply do something like this:



    // more things here
    using (var client = new HttpClient())

    client.BaseAddress = hostUri;
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
    var method = "PATCH";
    var httpVerb = new HttpMethod(method);
    var httpRequestMessage =
    new HttpRequestMessage(httpVerb, path)

    Content = stringContent
    ;
    try

    var response = await client.SendAsync(httpRequestMessage);
    if (!response.IsSuccessStatusCode)

    var responseCode = response.StatusCode;
    var responseJson = await response.Content.ReadAsStringAsync();
    throw new MyCustomException($"Unexpected http response responseCode: responseJson");


    catch (Exception exception)

    throw new MyCustomException($"Error patching stringContent in path", exception);







    share|improve this answer



























      0














      HttpClient does not have patch out of the box.
      Simply do something like this:



      // more things here
      using (var client = new HttpClient())

      client.BaseAddress = hostUri;
      client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
      var method = "PATCH";
      var httpVerb = new HttpMethod(method);
      var httpRequestMessage =
      new HttpRequestMessage(httpVerb, path)

      Content = stringContent
      ;
      try

      var response = await client.SendAsync(httpRequestMessage);
      if (!response.IsSuccessStatusCode)

      var responseCode = response.StatusCode;
      var responseJson = await response.Content.ReadAsStringAsync();
      throw new MyCustomException($"Unexpected http response responseCode: responseJson");


      catch (Exception exception)

      throw new MyCustomException($"Error patching stringContent in path", exception);







      share|improve this answer

























        0












        0








        0







        HttpClient does not have patch out of the box.
        Simply do something like this:



        // more things here
        using (var client = new HttpClient())

        client.BaseAddress = hostUri;
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
        var method = "PATCH";
        var httpVerb = new HttpMethod(method);
        var httpRequestMessage =
        new HttpRequestMessage(httpVerb, path)

        Content = stringContent
        ;
        try

        var response = await client.SendAsync(httpRequestMessage);
        if (!response.IsSuccessStatusCode)

        var responseCode = response.StatusCode;
        var responseJson = await response.Content.ReadAsStringAsync();
        throw new MyCustomException($"Unexpected http response responseCode: responseJson");


        catch (Exception exception)

        throw new MyCustomException($"Error patching stringContent in path", exception);







        share|improve this answer













        HttpClient does not have patch out of the box.
        Simply do something like this:



        // more things here
        using (var client = new HttpClient())

        client.BaseAddress = hostUri;
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
        var method = "PATCH";
        var httpVerb = new HttpMethod(method);
        var httpRequestMessage =
        new HttpRequestMessage(httpVerb, path)

        Content = stringContent
        ;
        try

        var response = await client.SendAsync(httpRequestMessage);
        if (!response.IsSuccessStatusCode)

        var responseCode = response.StatusCode;
        var responseJson = await response.Content.ReadAsStringAsync();
        throw new MyCustomException($"Unexpected http response responseCode: responseJson");


        catch (Exception exception)

        throw new MyCustomException($"Error patching stringContent in path", exception);








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 17:30









        iberodeviberodev

        3,61433466




        3,61433466



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39816829%2fhow-do-i-do-a-patch-request-using-httpclient-in-dotnet-core%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived