add_header ‘Access-Control-Allow-Origin‘ ‘*‘;
add_header ‘Access-Control-Request-Method‘ ‘GET,POST‘;
提示如下
has been blocked by CORS policy:
The value of the ‘Access-Control-Allow-Origin‘header in the response must not be the wildcard ‘*‘ when the request‘s credentialsmode is ‘include‘.
The credentials mode of requests initiated by the XMLHttpRequestis controlled by the withCredentials attribute.
在CORS中,Credential不接受http响应首部中的‘Access-Control-Allow-Origin’设置为通配符‘*’
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials
CORS 请求发出时,已经设定了credentials,但服务端配置了http响应首部 Access-Control-Allow-Origin 的值为通配符 ("*") ,而这与使用credentials相悖。
要在客户端改正这个问题,只需要确保发出 CORS 请求时将credential设置为false。
如果使用 XMLHttpRequest 发出请求,确保未将 withCredentials 设置为 true。
如果使用 Server-sent events, 确保 EventSource.withCredentials 的值为 false (false为默认值)。
如果使用 Fetch API,确保 Request.credentials 的值为 "omit".
如果还不成功,则需要修改服务端,可能需要修改** Access-Control-Allow-Origin** 的值,来为客户端所能够加载资源的源予以授权。
原文:https://www.cnblogs.com/fottencity/p/13411244.html