Axios always sends two requests and the first time there is an options request, how to get rid of it? I just want to have a request with token.

axios always sends two requests and the first time there is an options request, how to get rid of it?

the request header contains token

clipboard.png

Mar.24,2021

cannot be removed. The keywords simple request and non-simple request .


either do not use complex requests (such as get request)..) The complex request browser will send the pre-check command (options), which is the behavior of the browser and cannot be controlled.

I guess you are concerned that sending two HTTP requests feels a bit wasteful, so you can actually use Access-Control-Max-Age to cache the options for a certain period of time.

(to say something beside the point.. The front end is excused for not knowing HTTP , but it's a bit too much for the back end not to know the basics.)

related knowledge can be understood.


backend processing, post request will be sent twice, the first is with option, the second is post request, https://developer.mozilla.org.
part of the information, you can check this

Menu