Axios sends requests twice each time. What about one more Request Method: OPTIONS?

now axios is used in vue projects to send http requests. There will be one more Request Method: OPTIONS request for each request, followed by the get/post request. Is this a backstage problem or an axios request problem on my side? If the front desk can solve the problem, how should it be solved?

Sep.25,2021

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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34c12-2bf23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34c12-2bf23.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?