场景:
请求头设置token后页面报错:has been blocked by CORS policy:Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.
并且后台跨域相关已配置:Access-Control-Allow-Origin: *
解决:
需要后端在响应头的 Access-Control-Allow-Headers 字段设置允许前端请求时带有的字段值(检查了一下,在拦截器的响应里里增加如下)
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, accessToken, token");
Bug记录-Request header field token is not allowed by Access-Control-Allow-Headers...
最新推荐文章于 2024-10-11 09:54:15 发布