zoukankan      html  css  js  c++  java
  • java解决跨域

    方法中
    response.setHeader("Access-Control-Allow-Origin", "https://ding.taozugong.com"); response.setHeader("Access-Control-Allow-Methods","POST, GET, DELETE, PUT, PATCH, OPTION"); response.setHeader("Access-Control-Allow-Headers","token, Content-Type"); response.setHeader("Access-Control-Allow-Credentials", "true"); Controller层
    解决跨域注解 @CrossOrigin(origins
    = "*", maxAge = 3600)
     1 package com.taozugong.service;
     2 
     3 import org.springframework.context.annotation.Bean;
     4 import org.springframework.context.annotation.Configuration;
     5 import org.springframework.web.cors.CorsConfiguration;
     6 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
     7 import org.springframework.web.filter.CorsFilter;
     8 
     9 /**
    10  * @Author: lgy
    11  * @Date: 2018/7/2 20:33
    12  * @Description:
    13  */
    14 @Configuration
    15 public class CorsConfig {
    16     private CorsConfiguration buildConfig() {
    17         CorsConfiguration corsConfiguration = new CorsConfiguration();
    18         corsConfiguration.setAllowCredentials(true);
    19         corsConfiguration.addAllowedOrigin("https://shiyong.taozugong.com");
    20         corsConfiguration.addAllowedOrigin("https://zuyong.taozugong.com");
    21         corsConfiguration.addAllowedOrigin("https://newadm.taozugong.com");
    22         corsConfiguration.addAllowedOrigin("https://ding.taozugong.com");
    23         corsConfiguration.addAllowedHeader("*");
    24         corsConfiguration.addAllowedMethod("*");
    25         corsConfiguration.applyPermitDefaultValues();
    26         return corsConfiguration;
    27     }
    28 
    29     @Bean
    30     public CorsFilter corsFilter() {
    31         UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    32         source.registerCorsConfiguration("/**", buildConfig());
    33         return new CorsFilter(source);
    34     }
    35 }
  • 相关阅读:
    一个Package Load Failed问题的解决方法

    .NET相关的最好东西--全球最新评价
    一年了...
    MSBuild 的简单入门
    开发基于.NET Compact Framework的程序时, 常遇到的问题(2) 为什么在Visual Studio 2003调试程序时不能通过ActiveSync连接PDA
    如何:显示用逗号分隔的项集合(摘自MSDN)
    每日一句(2008.10.8)
    每日一句(2008.10.16)
    男人这辈子
  • 原文地址:https://www.cnblogs.com/walblog/p/9401379.html
Copyright © 2011-2022 走看看