Java中如何有效解决跨域资源共享问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1114个文字,预计阅读时间需要5分钟。
问题:在页面上要使用Ajax请求去获取另一个服务的的数据,由于浏览器的同源策略,直接请求会得到一个Error。错误信息:Failed to load https://www.baidu.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource.
问题
在页面上要使用 Ajax 请求去获取另外一个服务的数据,由于浏览器的 同源策略,所以直接请求会得到一个 Error。
Failed to load www.baidu.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
大概就是这样的一个错误,关键词是 Access-Control-Allow-Origin,一般出现这个都是跨域问题。
解决方案
解决跨域问题的方式有很多,但这里之说 Cors 的方案。
本文共计1114个文字,预计阅读时间需要5分钟。
问题:在页面上要使用Ajax请求去获取另一个服务的的数据,由于浏览器的同源策略,直接请求会得到一个Error。错误信息:Failed to load https://www.baidu.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource.
问题
在页面上要使用 Ajax 请求去获取另外一个服务的数据,由于浏览器的 同源策略,所以直接请求会得到一个 Error。
Failed to load www.baidu.com/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
大概就是这样的一个错误,关键词是 Access-Control-Allow-Origin,一般出现这个都是跨域问题。
解决方案
解决跨域问题的方式有很多,但这里之说 Cors 的方案。

