[转]When allowCredentials is true, allowedOrigins cannot contain the special value “*“

2021/12/17 23:25:37

本文主要是介绍[转]When allowCredentials is true, allowedOrigins cannot contain the special value “*“,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

前言

  项目接口访问出现allowedOrigins cannot contain the special value "*"

java.lang.IllegalArgumentException: When allowCredentials is true, 
allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. 
To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

修改方式

修改allowedOriginsallowedOriginPatterns

(1)修改前:

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            .allowCredentials(true)
            .maxAge(3600)
            .allowedHeaders("*");
}

(2)修改后:

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOriginPatterns("*")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            .allowCredentials(true)
            .maxAge(3600)
            .allowedHeaders("*");
}

原文链接:When allowCredentials is true, allowedOrigins cannot contain the special value “*“



这篇关于[转]When allowCredentials is true, allowedOrigins cannot contain the special value “*“的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程