当前位置:网站首页>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 headerOrigin
value , 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 totrue
when , 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 .
边栏推荐
- CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- Reptile exercises (I)
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- CA:用于移动端的高效坐标注意力机制 | CVPR 2021
- Read the BGP agreement in 6 minutes.
- "Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
- Read the BGP agreement in 6 minutes.
- Alibaba cloud award winning experience: build a highly available system with polardb-x
猜你喜欢
美团·阿里关于多模态召回的应用实践
C#/VB. Net to add text / image watermarks to PDF documents
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
Full arrangement (medium difficulty)
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
ISO 27001 Information Security Management System Certification
MDK在头文件中使用预编译器时,#ifdef 无效的问题
随机推荐
iptables基础及Samba配置举例
7、 Software package management
A taste of node JS (V), detailed explanation of express module
SQL statement syntax error in test SQL statement deletion in eclipse linked database
Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
Reading cognitive Awakening
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
AI 绘画极简教程
WPF double slider control and forced capture of mouse event focus
Rsyslog configuration and use tutorial
高效!用虚拟用户搭建FTP工作环境
Valentine's Day confession code
8个扩展子包!RecBole推出2.0!
XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
Besides, rsync+inotify realizes real-time backup of data
分布式事务相关概念与理论
Golang sets the small details of goproxy proxy proxy, which is applicable to go module download timeout and Alibaba cloud image go module download timeout
微服务入门
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?