The 'Access-Control-Allow-Origin' header contains multiple values
时间: 2023-08-24 07:11:35 浏览: 206
Allow CORS Access-Control-Allow-0.1.9.zip
The 'Access-Control-Allow-Origin' header contains multiple values错误是由于设置了相同的跨域信息导致的。解决办法可以参考以下方法:
1. 使用Spring Cloud Gateway解决双重跨域问题。在配置文件中添加以下内容:
```
spring:
cloud:
gateway:
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_UNIQUE
globalcors:
cors-configurations:
'\[/**\]':
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
allow-credentials: true
```
这样可以确保只有一个Access-Control-Allow-Origin头信息被设置。
2. 在Nginx配置中添加以下内容,更改客户端请求头,确保只有一个Access-Control-Allow-Origin头信息被设置:
```
location / {
proxy_set_header Origin '';
proxy_pass 123.com;
add_header Access-Control-Allow-Origin "*" always;
}
```
这样可以通过更改请求头来解决多个Access-Control-Allow-Origin头信息的问题。
请根据具体情况选择适合的解决办法。
#### 引用[.reference_title]
- *1* [跨域问题:The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘*‘, but only one is...](https://blog.csdn.net/qq_47768542/article/details/114371791)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [spring cloud解决双重跨域报错The ‘Access-Control-Allow-Origin‘ header contains multiple values , ...](https://blog.csdn.net/qq_37050372/article/details/126140638)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘null, *‘, but only one is ...](https://blog.csdn.net/huang_cheng_zhi/article/details/131101424)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文