background: A new colleague asked me that there were many options requests in my project, and the background services were down, and I didn’t know how to deal with it;
http protocol In fact, the most commonly used HTTP methods are: GET, POST; they can be used as data exchange between the front-end and the back-end; Under what circumstances do options appear
When the above three situations occur, options requests will appear. To put it simply, it is for server security. For example, the same-origin policy triggers this rule; Options are usually initiated automatically by the browser, and their purpose is to check whether the next method (GET, POST, PUT, delete) is supported by the server; How to deal with the server Check the following A: Method
If your project is considered safe, just return a 200 status code. B: Method
If your project is considered safe, just return a 200 status code. If not allowed you can put back status code 400 or something; Options requests affect service performance, how to optimize Originally, one request was enough to complete the task, but the frequent addition of many options inevitably caused pressure on the service; It is possible to cache options requests. For example, options requests will appear in the http://www.**.com/api/getUser interface. We cache options once when options are returned, and inform the front-end not to send options when requesting this interface in the future. When the server responds, the Access-Control-Max-Age time can be set, which is 10 minutes by default. Further understanding of options Functions of key fields related to options
MDN's description of OPTIONS The HTTP OPTIONS method is used to obtain the communication options supported by the target resource. The client can use the OPTIONS method for a specific URL or for the entire site (by setting the URL to "*"). |
<<: Four departments jointly issued a document, and 5G development has attracted attention again
>>: Network charges are more affordable and 5G demand is gradually released
"Survival of the fittest" is one of the...
In recent years, there is nothing like machine le...
In order to thoroughly implement the spirit of th...
With the implementation of 5G, the direction of m...
[51CTO.com original article] Enterprises have alw...
From February 15th to February 28th, Tencent Clou...
System administrators use Syslog or SNMP Trap for...
The large-scale deployment of IPv6 networks has b...
Have you ever complained in your heart about &quo...
According to the website of China Internet Networ...
【51CTO.com Quick Translation】 Geoffrey Moore'...
Until now, there are still a lot of voices in the...
spinservers has released several special packages...
I saw this company's information on LET. The ...
On May 23, 2023 , Beijing Motorola Solutions (Chi...