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

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page