我收到405错误消息:“请求的资源不支持http方法'OPTIONS'。”使用AngularJS。它部署在Azure中。
常规标题
Request URL: https://ao-uhe-demo.test.one/WebAPI/api/SaveSettings
Request Method: OPTIONS
Status Code: 405
Referrer Policy: no-referrer-when-downgrade
我的请求标头:
:authority: ao-uhe-demo.test.one
:method: OPTIONS
:path: /WebAPI/api/SaveSettings
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
access-control-request-headers: content-type
access-control-request-method: POST
origin: https://demo.test.one
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
响应标题:
access-control-allow-credentials: true
access-control-allow-headers: Origin, Content-Type, Content-Disposition,
Authorization
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin: https://demo.test.one
access-control-expose-headers: Content-Type, Content-Disposition
allow: GET,POST
cache-control: no-cache
content-length: 76
content-type: application/json; charset=utf-8
date: Thu, 06 Dec 2018 19:11:29 GMT
expires: -1
pragma: no-cache
server: Microsoft-IIS/10.0
status: 405
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
我在我的Web配置自定义标题中设置了
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Origin" value="https://demo.test.one" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Origin, Content-Type, Content-Disposition, Authorization" />
<add name="Access-Control-Expose-Headers" value="Content-Type, Content-Disposition " />
我在全局中拥有这个
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.End();
}
}