(跨域问题)Access to XMLHttpRequest at xxx from origin xxx

编程知识 更新时间:2023-04-06 10:28:46

问题:Access to XMLHttpRequest at ‘http://localhost:8181/book/findAll’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
解决方法:前端后端都可解决
①springboot后端:
创建配置类CorsConfig

@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","POST","HEAD","PUT","DELETE")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

更多推荐

(跨域问题)Access to XMLHttpRequest at xxx from origin xxx

本文发布于:2023-04-06 10:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/bee0d0114da8ecaa8fe72d3737d52e11.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XMLHttpRequest   Access   origin   xxx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 49057文章数
  • 14阅读数
  • 0评论数