Requirements: In the case of homologous origin, the frontend sends GET and POST requests to the backend interface, because the interface is public, it does not need to carry any authentication information, for example: when requesting cookie information, when using XMLHttpRequest, no matter how it is configured, the request cookie information cannot be deleted, which will cause the content of the request package to become larger, and it also wastes backend resources to parse, which is meaningless.
Whether you use native XMLHttpRequest or jQuery's Ajax to send a request to the backend, the cookie information of the request cannot be removed in the case of homologous, and the code is as follows:
BecausewithCredentials is designed for cross-domain。 As shown below:
Or carry cookies, wasting resource bandwidth and backend resources。
After modifying with fetch, the code looks like this:
The credentials are configured as follows:
omit: Never send credentials in a request and do not include credentials in a response.
same-origin(default): Only credentials that are sent and contain the same origin request.
include: Even for cross-domain access, be sure to include credentials.
Test request, very clean and refreshing, as shown below:
Reference:The hyperlink login is visible. |