跨域

1.什么是跨域
简单来说就是A网站试图访问B网站的内容,域名、协议以及端口任意一个不同,就是跨域访问。由于安全原因,跨域访问被各大浏览器禁止的,要想访问就必须通过相应方式建立两个服务器之间的关系,能够拿到想要的内容。
域名:
 主域名不同 http://www.baidu.com/index.html -->http://www.sina.com/test.js
 子域名不同 http://www.666.baidu.com/index.html -->http://www.555.baidu.com/test.js
 域名和域名ip http://www.baidu.com/index.html -->http://180.149.132.47/test.js
端口:
 http://www.baidu.com:8080/index.html–> http://www.baidu.com:8081/test.js
协议:
 http://www.baidu.com:8080/index.html–> https://www.baidu.com:8080/test.js

注意:
1)端口和协议不同,只能通过后台解决????
2)localhost和27.0.0.1虽然指向本机,但也属于跨域
3)JSONP、script、img、link、iframe不准在跨域请求的限制,可以利用他们解决跨域问题

3.怎么解决跨域
1)JSONP
2)CORS 跨域资源共享
3)proxy
4)ngnix反向代理
5)WebSoket 协议跨域
跨域问题的产生原因和相应的解决方式
https://blog.csdn.net/dreamcatcher1314/article/details/78652884 (分类清楚)
https://www.cnblogs.com/wangpenghui522/p/6284355.html

posted @ 2020-10-29 23:27  Redbreans  阅读(27)  评论(0)    收藏  举报