当前位置: 首页 > wzjs >正文

东莞市建设局门户网站百度关键词优化服务

东莞市建设局门户网站,百度关键词优化服务,哈尔滨微网站建设公司哪家好,外贸网站建设经验问题 SpringBoot3 中处理跨域请求 异常 浏览器在 localhost:3000 地址请求后端 http://127.0.0.1:8080 时, 报错提示 CORS 问题. 默认使用 Get 请求正常, 其他会提示. 使用 SpringBoot 3.4.2 版本配合 SpringSecurity 配置 Access to fetch at http://127.0.0.1:8080/todo-…

问题

SpringBoot3 中处理跨域请求

异常

浏览器在 localhost:3000 地址请求后端 http://127.0.0.1:8080 时, 报错提示 CORS 问题.
默认使用 Get 请求正常, 其他会提示.
使用 SpringBoot 3.4.2 版本配合 SpringSecurity 配置

Access to fetch at 'http://127.0.0.1:8080/todo-task/list' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

解决

需要在 Spring Security 配置以下内容…


/*** Spring Security 配置** @author Jion*/
@Configuration
@EnableWebSecurity
@AllArgsConstructor
public class SecurityConfig {private final JwtAuthenticationFilter jwtAuthenticationFilter;private final CustomAuthenticationEntryPoint unauthorizedHandler;/*** 配置过滤器链** @param http 请求* @return 过滤器链* @throws Exception 抛出异常*/@Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {// 一些其他配置等...// 跨域请求http.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource()));return http.build();}/*** 跨域配置, 仅在开发环境有必要.* 如果是发布之后, 桌面应用不会产生跨域问题.*/@Beanpublic UrlBasedCorsConfigurationSource corsConfigurationSource() {CorsConfiguration configuration = new CorsConfiguration();// 允许本地域名访问configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://127.0.0.1:3000"));// 允许被本地域名访问configuration.setAllowedOriginPatterns(Arrays.asList("http://localhost:3000/**", "http://127.0.0.1:3000/**"));// 允许所有请求方法configuration.setAllowedMethods(List.of("*"));// 允许所有请求头configuration.setAllowedHeaders(List.of("*"));// 允许所有响应头configuration.setExposedHeaders(List.of("*"));// 允许携带凭证configuration.setAllowCredentials(true);// 跨域请求配置UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();// 匹配所有请求路径source.registerCorsConfiguration("/**", configuration);return source;}
}
http://www.dtcms.com/wzjs/523497.html

相关文章:

  • 网页游戏网站建设google站长工具
  • 网站建设的服务器新闻网站软文平台
  • 代刷网站系统怎么做西安seo王
  • 网站建设销售常见问题怎么制作网站?
  • 手机网站制作 费怎么做分录火星时代教育培训机构官网
  • 网站界面设计应遵循的原则app拉新推广平台渠道
  • 深圳网站建设交易软文代发布
  • 网站售后服务内容b2b是什么意思
  • 做百度网络营销推广西安关键词seo
  • 龙岗网站建设费用百度2022第三季度财报
  • 姜堰网站定制推广平台
  • 网站管理系统安装四年级2023新闻摘抄
  • 静态网站托管百度广告投放价格表
  • 闲鱼钓鱼网站怎么制作网站设计公司怎么样
  • 西安seo外包价格哈尔滨百度关键词优化
  • 有没有做会计的网站百度优化教程
  • 中国空间站最新进展舟山百度seo
  • 有什么网站是layui做的福州seo管理
  • 2 网站建设的一般步骤包含哪些宁波百度seo点击软件
  • wordpress主题zhixina河北seo基础入门教程
  • 网站如何做淘宝支付宝支付百度推广找谁做靠谱
  • 网站建设的重要性seo搜索引擎优化方案
  • 张家港杨舍网站建设0元免费做代理
  • 响应式网站建设推广yandex引擎搜索入口
  • 图书馆 网站开发 总结app拉新项目一手渠道商
  • 医药平台网站建设sem竞价账户托管
  • 网站过期怎么办安徽网站建设优化推广
  • 公司网站网页制作建议自己在家做电商
  • 电脑网站和手机网站怎么做相同路径在线搜索资源
  • 网站建设入门教程pdfseo是什么级别