当前位置: 首页 > 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/308632.html

相关文章:

  • 用qq邮箱做网站百度网盘客服人工电话
  • wordpress 小米路由器seo是对网站进行什么优化
  • 网站如何做外部链接今日头条搜索优化怎么做
  • html用什么软件写代码seo工程师
  • 小萝做h视频网站深圳seo秘籍
  • 网站内置多语言济南优化网站的哪家好
  • 自己建设的网站靠谱吗好项目推荐平台
  • 顺义网站建设推广优化seo网络域名综合查询
  • 网站设计时尚必应搜索引擎网站
  • MATLAB 做网站搜狗网址导航
  • 网站备案 取名资讯通不过拓客公司联系方式
  • 盘石做的网站网盘网页版登录入口
  • 深圳有哪些网站是做餐饮沙龙的网坛最新排名
  • 沃尔玛超市seo教育
  • 找做玻璃的网站seo网站优化做什么
  • wordpress页脚居中seo推广话术
  • 宁波网站推广厂家排名网络销售靠谱吗
  • html5英文视频网站建设百度账号中心官网
  • 自适应网页模板建站seo查询爱站
  • 网站是用php还是asp 怎么区别焊工培训内容
  • 中盛浩瀚建设有限公司网站中关村在线app
  • 有多少个网站优化大师是什么
  • 公司网站怎么修改内容深圳网络推广平台
  • 网络营销案例2020海口网站关键词优化
  • 什么是网络视频营销专业网站优化培训
  • 宝安做棋牌网站建设哪家便宜广东省最新疫情
  • 旅游网站建设策划方案湖南网站seo
  • node.js可以做网站么教育培训机构网站
  • 山西太原网站建设seo搜索引擎实训心得体会
  • 昆明网站设计多少钱什么是百度权重