I have a .NET Core 2.0 WebApi application in which I have added the "Flurl.Http" (Version 2.1.0) NuGet package to my project.
I am trying to use Flurl to make a simple REST API call to one of Visual Studio Team Services' (VSTS) Api endpoints.
However, the particular VSTS api endpoint that I am calling requires that the Content-Type be set to "application/json-patch+json" instead of the typical "application/json".
In my Flurl call, I am using the "WithHeader()" method to try and set the Content-Type in the header of the request, but it is not working. Flurl seems to not allow me to override the default or standard Content-Type that is built into the PostJsonAsync method.
Does anyone know how to change the Content-Type of the request using Flurl? Or how to properly override the default behavior of the Content-Type in the Flurl configuration?
Thanks in advance!
My code:
public bool CreateNewBug(NewBugRequest newBugRequest)
{
return _apiUrlToCreateNewBug.WithHeader("Authorization", "Basic Base64PersonalAccessTokenGoesHere")
.WithHeader("Content-Type", "application/json-patch+json")
.PostJsonAsync(newBugRequest.Fields)
.Result
.IsSuccessStatusCode;
}
(This code works, but the response from the VSTS api is that the Content-Type is not allowed and needs to be changed to "application/json-patch+json", which is what I tried to set it to in the header.)
New answer: Upgrade to the latest Flurl.Http. The issue has been fixed in 2.3.1, so the code posted in the question (the cleanest approach) should actually work as expected now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With