What is the difference between these two calls? My end goal is to have
Accept: application/json
sent over the wire, not to append to some default set of other MIME types.
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
vs.
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
My CLR is .NET Core 2.0.
Sniffing the wire reveals no difference:
# just .Add("Accept"...
~ % nc -l 8000
GET / HTTP/1.1
Connection: Keep-Alive
Accept: application/json
[...]
# with MediaTypeWithQualityHeaderValue
~ % nc -l 8000
GET / HTTP/1.1
Connection: Keep-Alive
Accept: application/json
[...]
So, outside the bizarre naming of that type, nothing else to gain here right?
DefaultRequestHeaders
provides shortcuts to some of the most used headers likeAccept
. – BaillargeonAccept: text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5
– Baillargeon