Hack Forums
[C#] HttpClient / HttpRequestMessage adding white spaces to headers - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] HttpClient / HttpRequestMessage adding white spaces to headers (/showthread.php?tid=5969236)



HttpClient / HttpRequestMessage adding white spaces to headers - vaiperboy - May 12, 2019

https://stackoverflow.com/questions/55833095/httpclient-httprequestmessage-adding-white-spaces-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)


RE: HttpClient / HttpRequestMessage adding white spaces to headers - JUSTIN - May 12, 2019

Take a look at section 14 of RFC2616, aka IETF's official documentation for HTTP.
https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.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/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Net.Http/src/System/Net/Http/Headers/NameValueHeaderValue.cs#L183) you could also override the ToString method in the NameValueHeaderValue class.


RE: HttpClient / HttpRequestMessage adding white spaces to headers - Meterpreter - May 18, 2019

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";