0
点赞
收藏
分享

微信扫一扫

Access to XMLHttpRequest at ‘http://localhost:8443/api/logout‘ from origin ‘http://localhost:8080‘


问题:

Access to XMLHttpRequest at ‘http://localhost:8443/api/logout‘ from origin ‘http://localhost:8080‘_跨域


解决方案:

  1. 后端相关Controller添加跨域注解@CrossOrigin
  2. 后端新建配置类,实现WebMvcConfigurer接口,并重写addCorsMapping方法

@Override
public void addCorsMappings(CorsRegistry registry) {
//设置允许跨域的路径
registry.addMapping("/**")
//设置允许跨域请求的域名
.allowedOrigins("*")
//这里:是否允许证书 不再默认开启
.allowCredentials(true)
//设置允许的方法
.allowedMethods("*")
//跨域允许时间
.maxAge(3600);
}


举报

相关推荐

http://localhost:8080/hohode

json:报POST http://localhost:8080/testJson 415

0 条评论