不仅仅是fetch,只要你满足以下几种情况,都会去发起一个 Preflighted requests,也就是options请求,参见上面链接。
It uses methods other than GET, HEAD or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, ortext/plain, e.g. if the POST request sends an XML payload to the server using application/xmlor text/xml, then the request is preflighted.
It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)
你看看你是不是触发这几个条件中的其中一种了吧,浏览器在发起跨域请求的时候会带着一个`Origin` header,那么其实就是个custom headers,那么也就会先触发一个Preflighted requests,
Fetch Standard 也有提到。
---------------------
作者:弹琴弹琴
来源:CSDN
原文:https://blog.csdn.net/bbsyi/article/details/79023655
版权声明:本文为博主原创文章,转载请附上博文链接!