失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > gateway跨域 vue设置携带cookie

gateway跨域 vue设置携带cookie

时间:2020-10-07 15:04:45

相关推荐

gateway跨域 vue设置携带cookie

1.同源策略和跨域

先明白同源策略

/question/26376773

2.gateway设置跨域

官方通过配置文件,https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#cors-configuration

spring:cloud:gateway:globalcors:cors-configurations:'[/**]':allowedOrigins: "https://docs.spring.io"allowCredentials: trueallowedMethods:- GET

或者通过配置类,注意 allowCredentials(允许携带cookie) 为true, allowedOrigins(指定哪些域名可以访问) 不可以为"*"

这两种配置都可以,其中一种即可,如果配置了浏览器访问还有问题,则检查前端

@Configurationpublic class GatewayCorsConfiguration {@Beanpublic CorsWebFilter corsWebFilter(){CorsConfiguration config = new CorsConfiguration();config.setAllowCredentials(true);config.addAllowedMethod("*");config.addAllowedOrigin("*");config.addAllowedHeader("*");UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());source.registerCorsConfiguration("/**", config);return new CorsWebFilter(source);}}

3.vueaxios 设置携带cookie

设置withCredentials:true

或者这样

如果觉得《gateway跨域 vue设置携带cookie》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。