当前位置:网站首页>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 .
边栏推荐
- Alibaba cloud award winning experience: build a highly available system with polardb-x
- Full arrangement (medium difficulty)
- Talk about the design and implementation logic of payment process
- 比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
- Use fail2ban to prevent password attempts
- SQL statement syntax error in test SQL statement deletion in eclipse linked database
- WPF双滑块控件以及强制捕获鼠标事件焦点
- CTF竞赛题解之stm32逆向入门
- 从0到1建设智能灰度数据体系:以vivo游戏中心为例
- 「小技巧」给Seurat对象瘦瘦身
猜你喜欢
Practice: fabric user certificate revocation operation process
数据库锁表?别慌,本文教你如何解决
DGraph: 大规模动态图数据集
Meituan Ali's Application Practice on multimodal recall
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)
8 expansion sub packages! Recbole launches 2.0!
求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
一个数据人对领域模型理解与深入
Etcd storage, watch and expiration mechanism
随机推荐
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
WPF double slider control and forced capture of mouse event focus
ArcGIS uses grid processing tools for image clipping
「小技巧」给Seurat对象瘦瘦身
Why can the implementation class of abstractdispatcherservletinitializer be called when initializing the web container
runc hang 导致 Kubernetes 节点 NotReady
Runc hang causes the kubernetes node notready
n++也不靠谱
DGraph: 大规模动态图数据集
Etcd storage, watch and expiration mechanism
使用Scrcpy投屏
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
请问大佬们有遇到这个情况吗,cdc 1.4 连接MySQL 5.7 无法使用 timestamp
Runc hang causes the kubernetes node notready
Sort merge sort
Is the main thread the same as the UI thread- Is main thread the same as UI thread?
光环效应——谁说头上有光的就算英雄
从0到1建设智能灰度数据体系:以vivo游戏中心为例
二分查找的简单理解