问题: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
发布评论