问题
I'm using HTTPClient
in .netcore but I'm facing an issue when I add a custom accept header.
var client = new HttpClient { Timeout = new TimeSpan(0, 5, 0)};
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1");
But after this, what I see is that a space has been automaticaly added, resulting in "application/vnd.pagseguro.com.br.v3+json; charset=ISO-8859-1
". That space is causing me a trouble because the server return me an error. Without that space it works.
There is any way to remove that space in HttpClient
header? Conventional ways do not work, like trim
, or just a replace
once it's inside a DefaultRequestHeaders
and I can't modify directly.
回答1:
I was able to turnarround this issue by making a new microservice with .net Framework 4.5. Using HttpWebRequest, the header dont add an automaticaly space between the charset and accept.
Thanks for the help =D
回答2:
This is a bug in corefx.
Still open after 3 years!
https://github.com/dotnet/corefx/issues/39260
来源:https://stackoverflow.com/questions/40152607/httpclient-in-netcore-is-automatically-adding-a-space-in-header