Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

HttpClient / HttpRequestMessage adding white spaces to headers

https://stackoverflow.com/questions/5583...to-headers

I'm the creator of that request and seeking support here
Please suggest me stuff to do as I'm out of ideas, also newbies don't suggest stuff.

Spoiler (Click to View)

“I wish I could say everything in one word. I hate all the things that can happen between the beginning of a sentence and the end.” ~ Leonard Cohen
Take a look at section 14 of RFC2616, aka IETF's official documentation for HTTP.
https://www.w3.org/Protocols/rfc2616/rfc...html#sec14

The format that is actually being sent isn't wrong. Spacing shouldn't matter. In reality this is a problem with the site owner.
Regardless, I just tested Accept/Accept-Language headers via the WebClient class and they weren't modified before being sent.
If it's really a big problem you can try implementing that instead.

Since somebody on the Stackoverflow thread pointed out that this is hardcoded in CoreFX (https://github.com/dotnet/corefx/blob/a1...ue.cs#L183) you could also override the ToString method in the NameValueHeaderValue class.
I would personally recommend using WebClient.

For HttpClient and similar often make it difficult to set Host, Accept, and Content headers. WebClient is much easier. Also Justin is correct, spacing really shouldnt matter, the semi colons specific the break anyway not the space.

Webclient is literally 100 times easier:
Weblient wc = new WebClient();
wc.Headers[HttpRequestHeaders.Host] = "test";
wc.Headers[HttpRequestHeaders.Accept] = "";
And if you want to use a custom header its undoubtedly the easiest to use to do so:
wc.Headers["Custom-Header"] = "custom value";
All in on Ethereum


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by OxycodoneJul 20, 2022 12:19 AM 0 148 Jul 20, 2022 12:19 AM
Last Post: Oxycodone
[C#] by Nemo2478Aug 6, 2020 09:53 PM 1 163 Aug 6, 2020 09:53 PM
Last Post: Sonimnx
[C#] by draxyeeJul 12, 2020 10:06 PM 9 955 Jul 12, 2020 10:06 PM
Last Post: iolaka