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
The Internet of Things (IoT) is a technological r...
ServerHub is a long-established foreign hosting c...
Digital twins, or DTs, are data-enabled city mode...
[[182606]] In the discussion of 5G short code sol...
At the 2017 Huawei Analyst Conference in April 20...
【51CTO.com Quick Translation】CIOs of leading comp...
[[411615]] It has to be said that the development...
Sharing some information about Chinese VPS mercha...
Based on the principle of "using one generat...
[51CTO.com original article] Recently, Riverbed l...
After the rapid development in 2020, 2021 is a cr...
With the development of WiFi technology, WiFi has...
Entering the Internet age, the Internet allows pe...
[[266702]] Interviewer: What are the ways for par...
[[414626]] 1. Network Architecture There are many...