当前位置:网站首页>Cors: standard scheme of cross domain resource request
Cors: standard scheme of cross domain resource request
2022-07-04 13:20:00 【Boyue classmate】
CORS: Standard solution for cross domain resource requests
A previous article mentioned that we often encounter the failure of cross domain resource requests , Today, let's talk about the corresponding solutions .
First , Let's take a look at the solutions to cross domain problems .
1、 Using agents . principle : Between the cross domain knowledge browser and the server , Build a service that does not cross domain with your front end, and do data transfer by yourself , You can avoid the cross domain problem of directly teaching the target server about resource requests .
2、 Use jsonp. Principle utilization script The mechanism of downloading and executing tags and calling corresponding functions is implemented , Only some scenarios can be solved .
3、 utilize iframe, Use window.name Pass on the reference . Not very well understood .
4、CORS
Definition and Usage : It is one of the most common ways for modern browsers to support cross domain resource requests .
Usage method : Generally, it is necessary for the back-end personnel to process the request data , Add related operations that allow cross domain
For simple requests and complex requests , It can be divided into two situations .
For simple requests , The browser will add a origin Field , Automatically bring the source information of the request .
For complex requests , The browser will send a formal request , Send a options request , Pre check .
The server will add the following fields in the response message :
Access-Control-Allow-Origin( must ): This field is used to inform the browser that the server can send cross domain AJAX Requested domain , Its value is either this time AJAX Automatically added by the browser in the request headerOriginvalue , Or it can be a*Number , Indicates that any domain name request can be accepted ;Access-Control-Allow-Credentials( Optional ): This field is used to tell the browser whether the client is allowed to send to the server Cookie. By default ,CORS Specifications prevent cross domain AJAX Send to server Cookie, Therefore, the default value of this field isfalse, When you explicitly set the field value totruewhen , It means that cross domain is allowed this time AJAX Send to server Cookie.Access-Control-Expose-Headers( Optional ): This field is used to expose the available response header to the client ;
CORS Specifications stipulated , client XMLHttpRequest Object's getResponseHeader() Methods can only get 6 Basic fields :
* Cache-Control: Indicates the caching mechanism followed by the response ;
* Content-Language: The language that represents the response body ;
* Content-Type: Representing the response body MIME type ;
* Expires: Indicates the expiration time of the document , Expiration is no longer cached ;
* Last-Modified: Indicates the last change time of the document ;
* Pragma: Used to contain specific instructions ;
But when the client wants to get additional response header fields , The server needs to define the corresponding response header field name that can be obtained by the client after this field .
Of course , There are many detailed scenes , Especially for cookie Some of the treatment of .
But all in all , If you are a front end , Encounter the problem of cross domain resource request failure , If the back end says he can't change , Then he must be an entry-level dish chicken of wechat .
边栏推荐
- [leetcode] 96 and 95 (how to calculate all legal BST)
- Vit (vision transformer) principle and code elaboration
- 面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
- Read the BGP agreement in 6 minutes.
- Is the outdoor LED screen waterproof?
- eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
- 一个数据人对领域模型理解与深入
- Meituan Ali's Application Practice on multimodal recall
- 用fail2ban阻止密码尝试攻
- N++ is not reliable
猜你喜欢

Will the concept of "being integrated" become a new inflection point of the information and innovation industry?

求解:在oracle中如何用一条语句用delete删除两个表中jack的信息

干货整理!ERP在制造业的发展趋势如何,看这一篇就够了

Master the use of auto analyze in data warehouse

SQL statement syntax error in test SQL statement deletion in eclipse linked database

It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der

比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟

CTF竞赛题解之stm32逆向入门

7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多

ArcGIS uses grid processing tools for image clipping
随机推荐
PostgreSQL 9.1 飞升之路
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
7、 Software package management
6 分钟看完 BGP 协议。
WPF double slider control and forced capture of mouse event focus
在 Apache 上配置 WebDAV 服务器
Is the outdoor LED screen waterproof?
Excuse me, have you encountered this situation? CDC 1.4 cannot use timestamp when connecting to MySQL 5.7
使用 NSProxy 实现消息转发
Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
Configure WebDAV server on Apache
从0到1建设智能灰度数据体系:以vivo游戏中心为例
[Android kotlin] lambda return statement and anonymous function
AI painting minimalist tutorial
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
AI 绘画极简教程
go-zero微服务实战系列(九、极致优化秒杀性能)
Alibaba cloud award winning experience: build a highly available system with polardb-x
Rsyslog configuration and use tutorial
阿里云有奖体验:用PolarDB-X搭建一个高可用系统