我尝试使用以下代码发送带有$ http(angular)的http请求:
$http({
method: 'GET',
url: 'http://192.168.0.17:9000',
header: {'Access-Control-Allow-Origin': "*"},
}).then(getEventsSuccess, getEventsError);
但这不起作用,我在网络控制台中出现了这个错误:
XMLHttpRequest cannot load http://192.168.0.17:9000/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
你有解决方案吗?
答案 0 :(得分:4)
由于浏览器中实现了一种名为Same Origin Policy的安全机制,您会看到此错误。
基本上,这是因为您的网页试图访问位于与网页本身不同的主机,端口或方案(HTTP / HTTPS /文件等)上的服务器上的资源。
要解决此问题,您可以执行以下操作之一:
在这里阅读更多内容: https://en.wikipedia.org/wiki/Same-origin_policy https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS