Created attachment 12934 [details]
Changing the HttpClient.DefaultRequestHeader.Host or a HttpRequestMessage.Headers.Host has no effect.
The Host header is always taken from the request URL.
Using Windows (not on mono), the expected output is displayed:
Using DefaultRequestHeaders.Host: default-request-header-host
Using HttpRequestMessage.Headers.Host: http-request-message-host
Using Ubuntu 14.04 running Mono 4.0.2 and 4.2.0:
Using DefaultRequestHeaders.Host: localhost:5000
Using HttpRequestMessage.Headers.Host: localhost:5000
Steps to compile: mcs Program.cs /r:System.Net.Http
Steps to run: mono Program.exe
note: the HttpListener server included is for testing; it is not part of the problem
The fix is to explicitly set HttpWebRequest's Host field in HttpClientHandler.CreateWebRequest, as HttpWebRequest ignores the Host field in the list of headers.
Pull request at https://github.com/mono/mono/pull/2065
Fixed in master/5ec3345b799a0f29d6f7dea783ff25ca4f925c62 and mono-4.2/d983aa605a684d923d2104bd08fce0c8e2c53c6c
Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on GitHub
to continue tracking issues. Bugzilla will remain available for
reference in read-only mode. We will continue to work on open Bugzilla
bugs, copy them to the new locations as needed for follow-up, and add
the new items under Related Links.
Create a new report for Bug 34044 on Developer
Community or GitHub if you have new information to add and do not yet see a matching
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
Our sincere thanks to everyone who has contributed on this bug tracker
over the years. Thanks also for your understanding as we make these
adjustments and improvements for the future.