当前位置:网站首页>第3章 跨域问题
第3章 跨域问题
2022-07-26 22:36:00 【沉睡羊sleepysheep】
3-1 浏览器的同源策略



不能跨域名访问其他的资源
将这两个资源

复制到桌面上

更改地址
访问

点击不会返回结果


只认识localhost这个域名下的某页面发出的请求,这才符合同源策略
通过设置这个跨域访问的范围就可以决定哪个域名允许远程访问我的服务了




还有一些标签是不受同源策略要求的

3-2 CrossOrigin注解解决跨域访问




分别讲解,复制粘贴一份工程作为副本

打开配置webapp
修改端口号

![]()
打开
![]()
修改一下代码

向另外一个域80端口发送请求,不同端口下发送请求也会被视为跨域
启动,不会出现任何查询结果

我们是8080向80 端口发送请求就会产生跨域访问的问题![]()
在controller上声明一个跨域范围的注解

再次运行生效
![]()

如果有多个域名都需要跨域授权的话,该怎么做?
都加上就好了,依次追加
![]()
直接使用
![]()
代表所有都能访问
设置预检请求的缓存时间为3600秒
![]()
首先发送预检请求来向服务期确认请求是否允许访问,允许在发送时记得请求,不允许就中断,在每次发送的时候都会有两个请求,必然会增加服务期的压力,而且作为服务器端预检请求授权的逻辑是不会改变的,所以maxAge这个参数就起到作用了,可以将预检请求的结果进行缓存
在3600秒之内就不需要预检请求处理,直接发送实际请求
3-3 CORS全局配置

![]()
固然简单但是依旧存在问题,难以进行统一管理,需要一个能够全局配置的地方进行配置
打开applicationContext·进行设置
其实就是将刚才写的信息放到了xml文件中
测试一下


生效

只是在浏览器生效,小程序app不生效
专用于webapi只对外提供数据应用服务的web的话 用

只是个别的controller需要对外暴露服务的话用

两者都配置了的话会以注解的为准
边栏推荐
- Signal debugging document developed by car
- NFT display guide: how to display your NFT collection
- Kingbasees SQL language reference manual of Jincang database (3.1.1.14. scope type)
- Six challenges facing enterprise data governance!
- What are the use cases in the Internet of things industry in 2022?
- Problems and solutions encountered in using nextline(), nextint() and next() in scanner
- Everything you should know about wearable NFT!
- 2022.7.26-----leetcode.1206
- Azure Synapse Analytics 性能优化指南(4)——使用结果集缓存优化性能
- push to origin/master was rejected 错误解决方法
猜你喜欢
![[shader realizes shine effect _shader effect Chapter 3]](/img/ea/6c14f682e6157a96c1877d99c9f7d3.png)
[shader realizes shine effect _shader effect Chapter 3]

np. transpose & np.expand_ dims

Part II - C language improvement_ 11. Pretreatment
![[flask advanced] analyze the thread isolation mechanism in flask in combination with the source code](/img/11/27d354a411358bfb39ae7126f33a37.png)
[flask advanced] analyze the thread isolation mechanism in flask in combination with the source code
The memory occupation of the computer is too high after it is turned on (more than 50%)

Upload files to OSS file server

MVC three-tier architecture

04-传统的Synchronized锁

NFT display guide: how to display your NFT collection
![[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version](/img/70/5638080a2d2eabf6ae1f2a8db3abe6.png)
[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version
随机推荐
What is the reason for oom during redis shake synchronization in shake database?
2. Realize the map of navigation bar and battle page
push to origin/master was rejected 错误解决方法
Part II - C language improvement_ 8. File operation
Vector execution engine framework gluten announced the official open source and appeared at spark technology summit
实数范围内的求模(求余)运算:负数求余究竟怎么求
会议OA项目排座功能以及送审功能
Several inventory terms often used in communication
Number that cannot be bought
Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management
Force deduction 155 questions, minimum stack
Which securities company has the lowest commission? Is online account opening safe
04-传统的Synchronized锁
Public cloud security and compliance considerations
Download win10 system image and create virtual machine on VMware virtual machine
第二部分—C语言提高篇_12. 动/精态库的封装和使用
MySQL syntax uses detailed code version
8 other programming languages -- Recording
Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one
分页插件--PageHelper