当前位置:网站首页>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 .
边栏推荐
猜你喜欢

2022年中国移动阅读市场年度综合分析

Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing

Etcd 存储,Watch 以及过期机制

PostgreSQL 9.1 飞升之路

N++ is not reliable

C#/VB. Net to add text / image watermarks to PDF documents

Full arrangement (medium difficulty)

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

【云原生 | Kubernetes篇】深入了解Ingress(十二)

A data person understands and deepens the domain model
随机推荐
Sort merge sort
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
众昂矿业:为保障萤石足量供应,开源节流势在必行
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
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
聊聊支付流程的设计与实现逻辑
使用 NSProxy 实现消息转发
Is the outdoor LED screen waterproof?
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
Definition of cognition
8个扩展子包!RecBole推出2.0!
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
Besides, rsync+inotify realizes real-time backup of data
Vit (vision transformer) principle and code elaboration
Runc hang causes the kubernetes node notready
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
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)