Request uniRequest, will request twice

To the server is actually a preflight interfaces, default 5,6 seconds, may change their own
'Access-Control-Allow-Headers ', 'appId' to allow the server request carries for appId field, if there are other fields, can be used comma separated filled;

'Access-Control-Allow-Methods', ': POST, GET, OPTIONS' to allow the server allows the client to use POST, GET, and the OPTIONS method to initiate a request;

After the addition is complete, the corresponding increase in the response header fields can be successfully cross-domain communication with custom header fields.

1
2
3
4
5
6
//响应头局部:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Access-Control-Allow-Headers: appId
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Origin: *

However, we found that every time this situation will trigger OPTIONS request, and then go execute business logic, although the normal execution, but a request into two, and certainly increases the wait time for users and server resource consumption, so again in response headers added to Access-Control-Max-Age: 86400; response indicates that the effective time is 86400 seconds, which is 24 hours. The effective time, the browser without pre-screening for the same request to initiate the request again. The browser itself maintains a maximum effective time, if the value of the header field exceeds the maximum effective time, will not take effect. The last one interface on the same day only once OPTIONS request it, you're done!

Guess you like

Origin www.cnblogs.com/ydam/p/10983523.html