在解决之前在gateway中用了全局配置类跨域

package com.sky.wlmall.gateway.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;@Configuration
public class CorsConfig {@Beanpublic CorsWebFilter corsFilter() {CorsConfiguration config = new CorsConfiguration();config.addAllowedMethod("*");config.addAllowedOrigin("*");config.addAllowedHeader("*");UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());source.registerCorsConfiguration("/**", config);return new CorsWebFilter(source);}
}

之后却报错了:
报错提示:Access to XMLHttpRequest at ‘http://localhost:88/api/sys/menu/nav?t=1646366047125’ from origin ‘http://localhost:8001’ 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

将上面的配置类修改为如下,并配置yaml就解决了:

package com.sky.wlmall.gateway.config;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@SpringBootConfiguration
public class CorsConfig implements WebMvcConfigurer  {public void addCorsMappings(CorsRegistry corsRegistry){/*** 所有请求都允许跨域,使用这种配置就不需要* 在interceptor中配置header了*/corsRegistry.addMapping("/**").allowCredentials(true).allowedOrigins("http://localhost:8001").allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE").allowedHeaders("*").maxAge(3600);}}
spring:cloud:gateway:globalcors:add-to-simple-url-handler-mapping: truecors-configurations:'[/**]':allowedOrigins:- "http://localhost:8001"allowedMethods:- "GET"- "POST"- "DELETE"- "PUT"- "OPTIONS"allowedHeaders: "*"allowCredentials: truemaxAge: 360000

gateway跨域问题解决方法相关推荐

  1. vue跨域问题解决方法

    vue跨域解决方法 vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报"No 'Access-Control-Allow-Origin' ...

  2. Spring Boot2.x-13前后端分离的跨域问题解决方法之Nginx

    文章目录 概述 浏览器同源策略 后台搭建 pom.xml interceptor 配置 Controller 启动测试 浏览器和session 后端工程发布到服务器上 问题复现 通过Nginx反向代理 ...

  3. AJAX跨域问题解决方法(1)——禁止浏览器进行跨域限制

    思路:通过命令行修改浏览器启动参数,使得浏览器不进行跨域检查,从而允许跨域 方法:命令行参数启动浏览器后添加参数--disable-web-security 例: chrome --disable-w ...

  4. uni-app发布H5页面跨域问题解决方法

    uni-app提供了 最简单的 解决方案. 个人写的H5网页,因为没有服务器资源,所以需要经常调用其他网站的数据和资源,由于跨域问题,通常都无法访问其他网站.该方法非常适用于GET请求. 一.打开项目 ...

  5. vue-resource jsonp跨域问题解决方法

    最近在学习vue.js 碰到个ajax跨域请求的问题,之前知道可以用jsonp解决,但是一直没实践过,这次用发现里面好多问题,所以现在记录下来,希望可以给刚接触使用jsonp的同学一点帮助! 关于什么 ...

  6. npm run dev 在本地调试出现跨域问题解决方法

    npm run dev 在本地调试出现跨域问题 在localhost:8080调试时会出现跨域问题,如图: 我的项目是用webpack作为前端自动化构建工具,可以在webpack-dev-server ...

  7. 前端跨域问题解决方法

    1 什么是跨域? 协议,端口,域名三者之中有一个不同就会构成跨域 2 什么是同源? 同源指的就是协议,端口,域名三者一一对应,就算两个不同的域名指向同一个IP地址,也非同源,同源也是浏览器安全功能的一 ...

  8. vue-element-ui 中请求跨域问题解决方法

    找到 vue.config.js 把 默认红框中的内容注释掉改为黄框中的内容. 然后 更改 .env.development(开发配置文件),把 VUE_APP_BASE_API 中的内容改为 '/a ...

  9. Vue2前端请求API数据跨域问题解决

    Vue2前端请求API数据跨域问题解决方法 前端:Vue2 接口使用:API 问题报错提示: Access to XMLHttpRequest at 'http://localhost:9090/ec ...

  10. ssm把图片保存到项目中_项目中的图片跨域问题解决方式

    现象 首先,在生产环境中,由于进行编辑图片时,将图片回显到ReactCrop组件中进行可裁剪编辑,然而回显时,需要将图片转化为base64的格式或者blob对象, 此时需要将图片次绘制成canvas进 ...

最新文章

  1. TensorFlow(9)(项目)人马图像分类(卷积神经网络)
  2. oracle-sql汇总
  3. 亲测有用的音乐推荐网站
  4. linux安装weblogic9,linux_weblogic9_安装说明.doc
  5. rust为什么显示不了国服_Rust编程语言初探
  6. linux服务器组件有哪些,推荐几个linux服务器面板
  7. linux shell命令 复制,将bash提示符下的当前命令复制到剪贴板
  8. thinkphp的find()方法获取结果
  9. CPT205-Computer Graphics
  10. 如何不用密钥破解tableau
  11. DeepFaceLab AI换脸使用教程(1.安装及分解视频)
  12. ios7禁止屏幕旋转,强制竖屏
  13. PyCharm学生认证以及切换账号
  14. 如何给未来的自己写一封信(邮件) -- 方法
  15. 人工智能基础(高中版)教材补充和资源分享
  16. java使用knn实现mnist_java使用knn实现mnist - 百度学术
  17. 前端html通过鼠标操作进行样式的更改
  18. matlab插值与拟合(命令与示例),matlab插值与拟合(命令与示例)
  19. 给代码写注释时有哪些讲究?
  20. 最好PDF软件汇总070623

热门文章

  1. 闲鱼上卖什么东西一年赚了18万?
  2. 虚幻引擎 4 渲染流程分析
  3. DAOS整体设计分析 (二)
  4. CentOS 无法连接网络解决办法
  5. 计算机专业论文提纲,计算机硕士毕业论文提纲(范文精选)
  6. 第9章 保护Web应用----概念梳理
  7. 认知升级是比其他一切技能都更为重要的思维模式转变
  8. Windows网络共享方式
  9. COUNTIFS函数
  10. VDI IDV VOI