首页 > 数据库技术 > 详细

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

时间:2020-04-14 23:21:37      阅读:3867      评论:0      收藏:0      [点我收藏+]

出现这个,就是跨域问题了,我是在vue用axios直接发送请求向java后台的过程中出现的

然后我是在后端中解决的代码如下加上下面几个代码即可

@Configuration
public class WebConfig implements WebMvcConfigurer{


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 设置允许跨域的路径
        registry.addMapping("/**")
            // 设置允许跨域请求的域名
            .allowedOrigins("*")
            // 是否允许证书
            .allowCredentials(true)
            .allowedMethods("*")
            .maxAge(3600);
    }

        ...
}

 

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

原文:https://www.cnblogs.com/zzl521/p/12702018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!