fetch进行post请求为什么会首先发一个options 请求
2018-01-09 · 知道合伙人软件行家
不仅仅是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 也有提到。