Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

javascript - Why does Fetch API Send the first PUT request as OPTIONS

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

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?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See the Fetch Standard, section 4.7. CORS-preflight fetch.

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.

at steps 1 through 7; also 4.8. CORS-preflight cache.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...