[英]How does ASP.NET Web API “sort” Request Headers into Header Collections?
I was trying to read the value of the Content-Type
header in a custom delegating handler in ASP.NET Web API. 我试图在ASP.NET Web API的自定义委托处理程序中读取
Content-Type
标头的值。 When I queried the request.Headers
collection, the header value wasn't in there. 当我查询
request.Headers
集合时,标头值不在其中。 However, it was contained in request.Content.Headers
. 但是,它包含在
request.Content.Headers
。 Other non-standard headers (such as Content-Test
) starting with Content-
were available in request.Headers
only; 以
Content-
开头的其他非标准标头(例如Content-Test
)在request.Headers
中可用。 Content-Length
, on the other hand, could only be found within request.Content.Headers
, just like Content-Type
. 另一方面,
Content-Length
只能在request.Content.Headers
找到,就像Content-Type
。
Is it correct to assume that Web API is putting all known content headers into the request.Content.Headers
collection while putting all other headers into request.Headers
? 假设Web API将所有已知的内容标头放入
request.Content.Headers
集合,同时将所有其他标头放入request.Headers
是否正确?
That's how the HttpClient
was designed in the first place. 这就是
HttpClient
最初设计的方式。 Requests and responses are separate from the actual content hence content related cookies go into the HttpContent.Headers
rather than HttpRequestMessage.Headers
. 请求和响应与实际内容是分开的,因此与内容相关的cookie进入
HttpContent.Headers
而不是HttpRequestMessage.Headers
。 Keeping the content headers with the content is a good way of separating the concerns, on the other hand, getting to the content headers is a bit more cumbersome. 将内容标头与内容保持在一起是分离关注点的好方法,另一方面,访问内容标头则比较麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.