When attempting to access a resource cross-origin, developers often encounter issues related to the Access-Control-Allow-Origin header. The key to resolving these issues lies in understanding the precise meaning of "origin" in the context of the CORS protocol.
In CORS, an origin is a combination of a scheme, host (domain), and port. Importantly, it does not include a path. Therefore, the following two origins are considered distinct:
The problem in this particular case arises from a misunderstanding of the definition of origin. Specifically, the trailing slash in the allowed origin is not permitted according to CORS protocol specifications. As a result, the origin header sent by the browser (without the trailing slash) does not match the allowed origin configured on the server.
To resolve this issue, simply remove the trailing slash from the allowed origin value in your CORS configuration. In this case, the correct allowed origin would be:
With this modification, the browser's origin header will match the allowed origin, and CORS will be allowed successfully.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3