How does the ASP.NET Web API "sort" request headers in header collections?

I tried to read the value of the Content-Type header in the user delegation handler in the ASP.NET Web API. When I requested the request.Headers collection, the header value was not there. However, it was contained in request.Content.Headers . Other custom headers (such as Content-Test ) starting with Content- were only available in request.Headers ; Content-Length , on the other hand, could only be found in request.Content.Headers , just like Content-Type .

Is it correct to assume that the web API places all known content headers in the request.Content.Headers collection, putting all other headers in request.Headers ?

+4
source share
1 answer

The way the HttpClient design was developed in the first place. Requests and responses are separate from the actual content, so the files associated with the content are sent to HttpContent.Headers , not HttpRequestMessage.Headers . Storing content headers with content is a good way to share problems, on the other hand, getting content headers is a little more cumbersome.

+2
source

Source: https://habr.com/ru/post/1489680/


All Articles