当前位置:网站首页>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 .
边栏推荐
- A data person understands and deepens the domain model
- PostgreSQL 9.1 飞升之路
- 使用 NSProxy 实现消息转发
- 再说rsync+inotify实现数据的实时备份
- Apache服务器访问日志access.log设置
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- 提高MySQL深分页查询效率的三种方案
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- Deploy halo blog with pagoda
- 分布式事务相关概念与理论
猜你喜欢
Concepts and theories related to distributed transactions
PostgreSQL 9.1 soaring Road
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Etcd 存储,Watch 以及过期机制
Runc hang causes the kubernetes node notready
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
求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
CA:用于移动端的高效坐标注意力机制 | CVPR 2021
A data person understands and deepens the domain model
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
随机推荐
Vit (vision transformer) principle and code elaboration
AI 绘画极简教程
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
Valentine's Day confession code
Simple understanding of binary search
聊聊支付流程的设计与实现逻辑
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
Transformer principle and code elaboration (pytorch)
WPF double slider control and forced capture of mouse event focus
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
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
Etcd storage, watch and expiration mechanism
WPF双滑块控件以及强制捕获鼠标事件焦点
How real-time cloud interaction helps the development of education industry
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Reinforcement learning - learning notes 1 | basic concepts
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
Agile development / agile testing experience
Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements