What are OPTIONS?

The OPTIONS request method has two main uses:

  1. Obtain HTTP request methods supported by the server;
  2. It is used to check server performance. For example, AJAX prechecks cross-domain requests by sending an HTTP OPTIONS header to a resource with another domain name to determine whether the actual request sent is secure.

This is what the browser added to us, and the back end didn’t do anything.

2. Why do you use OPTIONS

An OPTIONS request is intended to send a “probe” request to determine what constraints the request must have for a target address (such as what HTTP method should be used and the custom request header), and then send the actual request based on those constraints. For example, the HTTP method used for Preflight requests for “cross-domain resources” is OPTIONS.

In short, the OPTIONS request method serves two main purposes:

  1. Obtain HTTP request methods supported by the server;
  2. It is used to check server performance.

3. When will the OPTIONS request be triggered?

A precheck request should be sent first (using OPTIONS) if any of the following conditions are met:

  1. One of the following HTTP methods is used:
PUT

DELETE

CONNECT

OPTIONS

TRACE

PATCH
Copy the code
  1. Header fields other than the set of header fields that are safe for CORS are manually set. The set is:
Accept Accept-Language Content-Language Content-Type (but note the additional requirements below) DPR Downlink Save-Data  Viewport-Width WidthCopy the code
  1. The value of content-type does not belong to one of the following:
application/x-www-form-urlencoded

multipart/form-data

text/plain
Copy the code

4, about the issue of triggering OPTIONS after returning 200 but not triggering a formal request

  1. Check whether the access-control-request-method specified in OPTIONS ‘Reponse headers is the same as that specified in the backend

  2. Check whether the access-control-Request-HEADERS user-defined headers field in the OPTIONS reponse Headers field is the same as the convention at the beginning of the backend

If there is a need to also can see nguyen teacher’s blog: www.ruanyifeng.com/blog/2016/0…