我使用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内部服务器错误.调试时收到以下错误:
{"Misused header name. Make sure request headers are used with HttpRequestMessage,response headers with HttpResponseMessage,and content headers with HttpContent objects."}
是否可以设置该标题?