zoukankan      html  css  js  c++  java
  • springboot vue前后端分离 跨跨域配置

    public class CustomCorsFilter extends OncePerRequestFilter {
    
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    
            response.setHeader("Access-Control-Allow-Origin", request.getHeader("origin"));
            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
            response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization, token");
            response.setHeader("Access-Control-Allow-Credentials", "true");
    
            response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
            filterChain.doFilter(request, response);
        }
    }
    @Configuration
    public class CorsConfig {
    
        @Bean
        public FilterRegistrationBean customCorsfilterRegistrationBean() {
            FilterRegistrationBean<CustomCorsFilter> filterRegistrationBean = new FilterRegistrationBean<>();
            filterRegistrationBean.setFilter(new CustomCorsFilter());
            filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
            filterRegistrationBean.addUrlPatterns("/*");
    
            return filterRegistrationBean;
        }
    }
  • 相关阅读:
    Django_rest_framework
    Django之FBV / CBV和中间件
    数据库之MySQL补充
    数据库之Python操作MySQL
    数据库之MySQL进阶
    数据库之初识MySQL
    2-3、配置Filebeat
    2-2、安装Filebeat
    2-1、FileBeat入门
    5、Filebeat工作原理
  • 原文地址:https://www.cnblogs.com/dingyingsi/p/11561430.html
Copyright © 2011-2022 走看看