简体   繁体   English

ASP.NET Web API如何将请求标头“排序”到标头集合中?

[英]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.

相关问题 ASP.NET Web API:更改请求标头 - ASP.NET Web API: Change Request Headers 预检响应中的 Access-Control-Allow-Headers 不允许 ASP.Net WEB API 请求标头字段授权 - ASP.Net WEB API Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response ASP.NET Web API获取请求标头 - Asp.net Web Api get request header 如何在 ASP.Net 中为一组 Web 请求发送身份验证标头 - How to send authentication header in ASP.Net for set of web request ASP.NET Web API请求未达到控制器操作 - ASP.NET Web API request does not reach controller action ASP.NET 5(vNext)Web API:如何构建授权标头? - ASP.NET 5 (vNext) Web API: How to build authorization header? ASP.NET如何确定此请求是针对WebForms页面还是MVC应用程序或Web API? - How does ASP.NET decide that this request is for a WebForms page or an MVC app or a Web API? 无法从ASP.NET Web API中的jQuery AJAX请求获取标头 - Unable to get headers from jQuery AJAX request in ASP.NET Web API 发送到ASP.NET Web API时,请求标头中Angular 5缺少Content-type - Angular 5 missing Content-type in request headers when send to ASP.NET Web API 如何在ASP.NET Web API中获取uri的请求对象? - How to get the request object for uri in ASP.NET Web API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM