问题
Access to XMLHttpRequest at 'http://localhost:8080/ws' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
回答1:
When invoking an XMLHttpRequest
, the browser makes a preflight request and checks for an Access-Control-Allow-Origin header to determine whether the request should be allowed. You should edit your server code to send that header with a value that allows the domain of your client (or just *
to allow CORS requests from any origin). For example, if using a Node server with Express, you could do res.set('Access-Control-Allow-Origin', '*')
来源:https://stackoverflow.com/questions/59814215/access-to-xmlhttprequest-has-been-bloked-by-cors-policy