Why does post send two requests

I read Nuggets’ article today. JD.com asked this question in an interview. I was also curious and wanted to understand the content of this piece, so I did the following to understand:

The request is a pair of requests, one request is a pre-request (preflight request), and its request method is options

Firefox browser can see this, chrome can also see this, when Network selects All

 That is, an OPTIONS request will be sent before the formal request, and then the real request

Maybe you usually filter out the fetch/XHR directly, so you can’t see the preflight request

The pre-request is because of cross-domain. It is fine to make a proxy configuration without crossing domains. Just use a proxy. Configure nginx. Or vue-cli can configure proxy

Guess you like

Origin blog.csdn.net/qq_37299479/article/details/132540027