后端使用@CrossOrigin页面还显示跨域问题?

后端使用@CrossOrigin页面还显示跨域问题?

前后端分离项目,后端设置的允许跨域的代码,到前端调试界面的时候还显示了不允许跨域。
在这里插入图片描述

错误信息如下:

Access to XMLHttpRequest at‘http://localhost:8000/carInfo/carCondition/1/4’ from origin‘http://localhost:9528’ has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
在这里插入图片描述

解决方案:

withCredentials: false

在这里插入图片描述

跨域问题解决:

在这里插入图片描述

原因:

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

@CrossOrigin 源码:
在这里插入图片描述

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值