http - 是否可以使用 ASP.NET WebApi 为 HEAD 响应设置 Allow header ?

标签 http asp.net-web-api

我正在构建一个 REST API 并尝试在收到 HEAD 请求时为特定路由返回 405 Method Not Allowed。

rules说“响应必须包含一个允许 header ,其中包含所请求资源的有效方法列表。”

然而,rules还说“服务器不得在响应中返回消息正文。”

因此,我正在构造我的 HttpResponseMessage,其 Content 属性为 null,但我可以提供“允许” header 的唯一方法是作为内容 header 。如果我尝试将其作为 HttpResponseMessage 对象而不是 HttpContent 对象的 header 提供,我会收到错误消息:

Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

那么是否有可能遵守规范,或者它是否属于“屏住呼吸”的情况之一?

最佳答案

尝试发送带有您的 header 和零长度字节数组的 ByteArrayContent

关于http - 是否可以使用 ASP.NET WebApi 为 HEAD 响应设置 Allow header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30063713/

相关文章:

http - Wireshark HTTP 跟踪

c# - MVC 4 WebAPI 中的操作

javascript - Web API - 无法加载资源 : the server responded with a status of 404

c++ - 我正在使用 cometd 服务器,我希望它与 C++ 交互

rest - 不允许对 Tomcat 服务器的 ExtJS PUT 请求

Android SDK管理器错误下载中断: Unexpected HTTP Status 503

php - WampServer 3.2.3 无法访问局域网,

c# - 如何使用分页方法

c# - 使用 Owin 在自托管的 Web API 中获取远程主机 IP

c# - Web API 和取消 token