我使用 ASP.NET Web Api 编写了一个 RESTful API。现在我试图让它返回控制器允许的动词。我正在尝试使用以下代码来做到这一点:
[AcceptVerbs("OPTIONS")]
public HttpResponseMessage Options()
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Headers.Add("Access-Control-Allow-Origin", "*");
response.Headers.Add("Access-Control-Allow-Methods", "POST");
response.Headers.Add("Allow", "POST");
return response;
}
但是,我没有在我的回复中获得允许标头,而是获得了500 Internal Server Error
. 在调试时,我收到以下错误:
{"Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects."}
可以设置该标题吗?