zoukankan      html  css  js  c++  java
  • spring boot 中 2.X 的跨域请求

    解决跨域:

    @Configuration
    @EnableAutoConfiguration
    public class ZooConfiguration {
       @Bean
        public FilterRegistrationBean<CorsFilter> corsFilter() {
       
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            CorsConfiguration config = new CorsConfiguration();
            config.setAllowCredentials(true);
            config.addAllowedOrigin("*");
            config.addAllowedHeader("*");
            config.addAllowedMethod("*");
            source.registerCorsConfiguration("/**", config);
            FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(source));
            bean.setOrder(0);
            return bean;
        }
    }

    1.什么是跨域?

    跨域: 指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器对 JavaScript 施加的安全限制。

    例如: a 页面想要获取 b 页面是资源,如果 a、b 页面的协议、域名、端口、子域名不同,所进行的访问行动都是跨域的,浏览器为了安全问题都限制了跨域的访问,也就是不允许跨域请求资源。跨域限制访问是浏览器限制的。

    同源策略: 指协议、域名、端口都要相同,其中有一个不同都会产生跨域。

     

    2.如何解决跨域问题

  • 相关阅读:
    Openlayer 3 的画图测量面积
    Openlayer 3 的画线测量长度
    屏幕尺寸
    px和em,rem的区别
    水平和垂直居中
    Flex布局
    继承的几种方法及优缺点
    call ,apply 和 bind的用法与区别
    mybatis springmvc velocity的demo
    正则同时包含两个关键字
  • 原文地址:https://www.cnblogs.com/bytecodebuffer/p/11251815.html
Copyright © 2011-2022 走看看