解决No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. If an opaque respons

Access to fetch at 'http://localhost:9090/user/list' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

解决方法:

1.找到对应的controller,加上注解

@CrossOrigin

 

 

这个错误是由于CORS(跨域资源共享)策略导致的。当你在前端发起一个跨域请求时,如果被请求的资源没有设置'Access-Control-Allow-Origin'头部,就会出现这个错误。\[1\]这个错误的具体信息是"No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled." \[1\] 解决这个问题的方法有几种。一种是在后端的响应中设置'Access-Control-Allow-Origin'头部,允许特定的域名访问资源。这样前端的请求就会被允许访问了。\[2\]另一种方法是在前端的请求中设置请求的模式为'no-cors',这样可以绕过CORS策略,但是会导致响应变为不透明的,无法获取到具体的响应内容。\[1\] 需要注意的是,CORS策略是为了保护用户的安全和隐私,所以在设置'Access-Control-Allow-Origin'头部时,应该谨慎选择允许访问的域名,避免出现安全问题。\[2\]同时,如果你是在开发环境中遇到这个问题,可以考虑使用代理服务器来解决跨域请求的问题。\[3\] #### 引用[.reference_title] - *1* [解决No ‘Access-Control-Allow-Originheader is present on the requested resource. If an opaque ...](https://blog.csdn.net/qinleilei7760631/article/details/130027251)[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* [No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问的解决方法](https://blog.csdn.net/xujinggen/article/details/83999391)[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* [处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题](https://blog.csdn.net/qq_37647296/article/details/89401499)[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 ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Riqk_Qin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值