My research says that this is a bad thing to do. Content-Type is explicitly intended for use with messages that have content, eg. POST, PUT, and (maybe?) PATCH.
Unfortunately, another team at my company decided that they would require Content-Type on all HTTPS requests made to their REST API, and the chances of that changing are close to nil, even though this violates RFC 7231 Section 3.1.5.5.
(For reference, they decided that "Content-Type" would be used to specify which version of their API the call expects to use.)
When I try to do
HttpClient myHttpClient = new HttpClient() //code simplified for brevity
myHttpClient.DefaultRequestHeaders.Add("Content-Type", "application/json; version=3.0");
I get a runtime exception:
When I try:
myHttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; version=3.0");
The Content-Type header doesn't seem to get added.
What can I do?