Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[软技能] 第1078天 接口请求的Type显示preflight表示什么呢? #5022

Open
haizhilin2013 opened this issue Mar 28, 2022 · 1 comment
Labels
软技能 软技能

Comments

@haizhilin2013
Copy link
Collaborator

第1078天 接口请求的Type显示preflight表示什么呢?

3+1官网

我也要出题

@haizhilin2013 haizhilin2013 added the 软技能 软技能 label Mar 28, 2022
@LstHeart
Copy link

preflight request是为确保服务器是否允许发起对服务器数据产生副作用的HTTP请求方法,而预先由浏览器发起OPTIONS方法的一个预检请求,如果允许就发送真实的请求,如果不允许则直接拒绝发起真实请求。通常preflight请求不需要用户自己去管理和干预,它的发出的响应都是由浏览器和服务器自动管理的。

MDN上指出,一共有五项必须条件需要满足,否则浏览器在执行真实请求之前会发出预检请求,以免在获得允许之前对服务器产生不可预知的影响。 以下五项条件只要有任意一项不满足即会发送预检请求:
1.请求方法限制:只能够使用GET POST HEAD
2.只能包含九种请求头: Accept、 Accept-Language 、Content-Language 、Content-Type、 DPR 、Downlink 、Save-Data 、Viewport-Width 、Width
3.Content-Type限制:Content-Type只能包含三种类型: text/plain、multipart/form-data 、application/x-www-form-urlencoded
4.XMLHttpRequestUpload对象没有注册任何事件监听器
5.请求中不能使用ReadableStream对象

preflight请求是CORS规范的一部分,只有在跨域的前提下,才会触发preflight请求的条件,如果请求没有跨域,即使请求不符合preflight请求的五项限制条件,也不会触发。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
软技能 软技能
Projects
None yet
Development

No branches or pull requests

2 participants