Access to XMLHttpRequest has been bloked by CORS policy

一个人想着一个人 提交于 2021-02-09 08:58:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!