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
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
add a comment |
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
2
use aHttpRequestMessage
– 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
add a comment |
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
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
dotnet-httpclient http-patch
asked Oct 2 '16 at 12:07
Tom AalbersTom Aalbers
1,30721331
1,30721331
2
use aHttpRequestMessage
– 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
add a comment |
2
use aHttpRequestMessage
– 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
add a comment |
2 Answers
2
active
oldest
votes
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
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
add a comment |
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);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 8 at 17:30
iberodeviberodev
3,61433466
3,61433466
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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