为什么Fetch API将第一个PUT请求作为OPTIONS发送 [英] Why does Fetch API Send the first PUT request as 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.
这篇关于为什么Fetch API将第一个PUT请求作为OPTIONS发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!