当前位置:网站首页>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 .
边栏推荐
- PostgreSQL 9.1 飞升之路
- iptables基础及Samba配置举例
- 7、 Software package management
- runc hang 导致 Kubernetes 节点 NotReady
- Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
- Transformer principle and code elaboration (tensorflow)
- Rsyslog configuration and use tutorial
- CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
- Vit (vision transformer) principle and code elaboration
- 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
猜你喜欢

《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话

6 分钟看完 BGP 协议。

众昂矿业:为保障萤石足量供应,开源节流势在必行

Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?

强化学习-学习笔记1 | 基础概念

runc hang 导致 Kubernetes 节点 NotReady

PostgreSQL 9.1 soaring Road

Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow

After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)

阿里云有奖体验:用PolarDB-X搭建一个高可用系统
随机推荐
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
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
高效!用虚拟用户搭建FTP工作环境
Transformer principle and code elaboration (pytorch)
WPF double slider control and forced capture of mouse event focus
七、软件包管理
After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话
微服务入门
WPF双滑块控件以及强制捕获鼠标事件焦点
强化学习-学习笔记1 | 基础概念
[AI system frontier dynamics, issue 40] Hinton: my deep learning career and research mind method; Google refutes rumors and gives up tensorflow; The apotheosis framework is officially open source
「小技巧」给Seurat对象瘦瘦身
Rsyslog configuration and use tutorial
使用Scrcpy投屏
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
一文掌握数仓中auto analyze的使用
[Android kotlin] lambda return statement and anonymous function
Annual comprehensive analysis of China's mobile reading market in 2022
Two dimensional code coding theory