From aced7bea8d0c729700a196fa54169dfa54cf47e1 Mon Sep 17 00:00:00 2001 From: wangkang Date: Thu, 1 Jun 2017 11:19:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 6.md | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 6.md diff --git a/6.md b/6.md new file mode 100644 index 0000000..2c9001f --- /dev/null +++ b/6.md @@ -0,0 +1,246 @@ +# spring boot / cloud (六) 开启CORS跨域访问 + +##前言 + + +###什么是CORS? + + +>Cross-origin resource sharing(跨域资源共享),是一个W3C标准,它允许你向一个不同源的服务器发出XMLHttpRequest请求,从而克服了ajax只能请求同源服务的限制.并且也可以通过灵活的设置,来指定什么样的请求是可以被授权的. + + +###什么是跨域? + + +假设你在http://xxx.com/test/下有一个js文件,从这个js里发出一个ajax请求请求后端服务,按照如下情况判定: + + +| 请求地址 | 原因 | 结果 | +| ------------- |:-------------:| -----:| +| http://xxx.com/xxxx/action | 同一域名,不同文件夹 | 非跨域 | +| http://xxx.com/test/action | 同一域名,同一文件夹 | 非跨域 | +| http://a.xxx.com/test/action | 不同域名,文件路径相同 | 跨域 | +| http://xxx.com:8080/test/action | 同一域名,不同端口 | 跨域 | +| https://xxx.com/test/action | 同一域名,不同协议  | 跨域 | + + +###还有那些其他的跨域解决方案? + + +- **JSONP** : 动态添加一个`