加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – IONIC,Access-Control-Allow-Origin

发布时间:2020-12-17 07:51:12 所属栏目:安全 来源:网络整理
导读:我尝试使用此代码发送带有$http(angular)的http请求: $http({ method: 'GET',url: 'http://192.168.0.17:9000',header: {'Access-Control-Allow-Origin': "*"},}).then(getEventsSuccess,getEventsError); 但这不起作用,我在Web控制台中出现此错误: XMLHtt
我尝试使用此代码发送带有$http(angular)的http请求:
$http({
              method: 'GET',url: 'http://192.168.0.17:9000',header: {'Access-Control-Allow-Origin': "*"},}).then(getEventsSuccess,getEventsError);

但这不起作用,我在Web控制台中出现此错误:

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.

你有解决方案吗 ?

由于浏览器中实现了一种称为Same Origin Policy的安全机制,您会看到此错误.

基本上,它是由于您的网页尝试访问驻留在与网页本身不同的主机,端口或方案(HTTP / HTTPS /文件等)上的服务器上的资源而引起的.

要解决此问题,您可以执行以下操作之一:

>从您尝试访问的服务器提供网页.如果您的网页网址为http://192.168.0.17:9000/X.html,则您的请求应该会成功,错误就会消失.
>为从服务器发送的响应添加一个特殊标头,称为Access-Control-Allow-Origin.

在这里阅读更多:
https://en.wikipedia.org/wiki/Same-origin_policy
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读