When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that canno
时间: 2023-11-02 08:52:37 浏览: 232
t be used in conjunction with credentials. Instead, you must specify the exact origins allowed to access the resource with credentials. This is because the Access-Control-Allow-Origin header, which is used to indicate allowed origins, must match the Origin header sent by the client. When credentials are involved, the Origin header is not sent if the allowed origins are set to “*“, which prevents the server from verifying the origin of the request. Therefore, to use credentials, you must specify the exact allowed origins.
相关问题
When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set o
当allowCredentials为true时,allowedOrigins不能包含特殊值"*",因为它不能设置在"Access-Control-Allow-Origin"响应头中。要允许凭据到一组来源,必须显式列出它们或考虑使用"allowedOriginPatterns"代替。
这个错误通常在Java应用程序中处理CORS(跨域资源共享)时出现。CORS是一种安全机制,用于限制跨域请求。当allowCredentials设置为true时,允许源的值不能为"*",而是需要明确指定允许的来源。
在修改方式中,将allowedOrigins修改为allowedOriginPatterns即可解决此问题。修改后的代码如下:
@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 "*"
当`allowCredentials`为`true`时,`allowedOrigins`不能包含特殊值"*",因为它不能设置在"Access-Control-Allow-Origin"响应头中。[1]<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [SpringBoot跨域问题:When allowCredentials is true, allowedOrigins cannot contain the special value ...](https://blog.csdn.net/qq_62767608/article/details/127416933)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [【解决】When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since](https://blog.csdn.net/m0_55710969/article/details/123626123)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文