首页 > 其他 > 详细

nginx 跨域出现以下报错

时间:2020-07-31 18:45:15      阅读:201      评论:0      收藏:0      [点我收藏+]

如何添加跨域

nginx

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** 的值,来为客户端所能够加载资源的源予以授权。

nginx 跨域出现以下报错

原文:https://www.cnblogs.com/fottencity/p/13411244.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!