为什么Fetch API将第一个PUT请求作为OPTIONS发送 [英] Why does Fetch API Send the first PUT request as OPTIONS

查看:169
本文介绍了为什么Fetch API将第一个PUT请求作为OPTIONS发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vanilla cors PUT请求/ API / Fetch_APIrel =nofollow noreferrer>获取API

I am trying to make a cors PUT request using the vanilla Fetch API

当我单击我的按钮发送PUT请求时,第一个请求的方法是 OPTIONS 。只有当我再次单击该按钮时,请求上的方法才会更改为 PUT 。为什么?

When I click my button to send the PUT request, the method on the first request is OPTIONS. It is only when I click the button again, then the method on the request changes to PUT. Why?

我知道这是CORS预检的一部分,但有没有办法手动触发预检,以便可以缓存OPTIONS响应?

I understand this is part of the CORS preflight, but is there a way to trigger the preflight manually so the OPTIONS response can be cached?

这种行为是否表明某处失败的承诺?

Could this behavior be indicative of a failing promise somewhere?

推荐答案

参见获取标准 4.7。 CORS-preflight fetch


注意:这实际上是用户代理的实现检查是否了解 CORS协议。所谓的 CORS-preflight请求。如果成功,它会填充 CORS-preflight缓存以最大限度地减少这些数量在步骤1到7中提取。

Note: This is effectively the user agent implementation of the check to see if the CORS protocol is understood. The so-called CORS-preflight request. If successful it populates the CORS-preflight cache to minimize the number of these fetches.

;还 4.8。 CORS-preflight缓存

这篇关于为什么Fetch API将第一个PUT请求作为OPTIONS发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆