Why is the OPTIONS request sent?
in fact, cross-domain is divided into simple cross-domain request
and complex cross-domain request
simple cross-domain request request will not send
complex cross-domain request request will send a pre-check request options
complex cross-domain request to meet the following requirements:
1. Request method is not required. Multipart/form-data, or text/plain
3. The request has a custom header
field
if you don't want to send a option
request, you can change it to a simple request. For example, your Content-Type
may be application/json
format and change it to application/x-www-form-urlencoded
.
this is a pre-check request before a non-simple request, and it is normal to request information such as the methods supported by the backend API. It does not need to be processed by the frontend, but the backend needs to uniformly handle and release the OPTIONS method for all APIs (that is, 200 is returned).
about simple requests and non-simple requests can be understood by Baidu.
how to handle cross-domain, whether CORS,options is a pre-check request. It doesn't matter. Check whether your parameters are compliant. You can learn about this cross-domain method
if you don't want to appear, you can consider jsonp to solve cross-domain. And npm also has a module of jsonp
options request will appear when cross-domain, and get post request will be made only after options is successful.