无法从虚拟机中安装的Orion Context代理获取数据

时间:2015-06-04 19:48:50

标签: fiware-orion

编辑: 每当我尝试从安装在虚拟机中的orion上的Orion上下文代理获取数据时,我会收到以下错误。 我使用的查询:

$.ajax({
    url: "http://a.b.c.d:1234/ngsi10/contextEntities/entity_name",
         headers: {
        'X-Auth-Token' : "Sabcdekdnbhhjh",
         'Accept' : "application/json; charset=utf-8", "Content-Type": "application/json; charset=utf-8" 
       },
       type: 'GET',
    contentType: 'application/json',
    success: displayAll,
    error: function(){
      console.log("Cannot get data");
    }
}); function displayAll(data){console.log(data);}

我收到此错误:

OPTIONS http://a.b.c.d:1234/ngsi10/contextEntities/"entityname" 
index .html:1 XMLHttpRequest cannot load http://a.b.c.d:1234/ngsi10/contextEntities/"entityname". No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405.
VM1513:12 Cannot get data

我正在使用“/etc/init.d/contextBroker start”来启动contextbroker和 输出ps ax | grep contextBroker是

1950 ?        Ss     0:00 /usr/bin/contextBroker -port 1026 -logDir /var/log/contextBroker -pidpath /var/run/contextBroker/contextBroker.pid -dbhost 83.212.238.114 -db orion -corsOrigin __ALL
 2560 ?        Ssl    0:00 contextBroker
 2678 pts/0    S+     0:00 grep contextBroker

当我传递所有标头并从虚拟映像或猎户座中安装的pep-proxy获取令牌时。提前谢谢。

1 个答案:

答案 0 :(得分:0)

问题在于包括" X标题"在请求中(特别是X-Auth-Token标头)导致AJAX启动预检CORS协议。该协议使用OPTION方法,Orion Context Broker目前不支持该方法(参见the following issue)。

有两种可能的解决方法:

  1. 删除X-Auth-Token标题(即直接访问Orion而不使用中间PEP)

  2. 使用后端代理此类请求。 This project似乎很有希望(虽然我没有亲自测试过):

  3.   

    客户端 - Orion Context Broker的服务器通信的代理   FIWARE平台中的跨域请求。

    编辑:完整的CORS支持包括Preflight已在Orion中针对所有NGSIv2请求实施。它现在可以在主分支机构或官方泊坞机中使用,很快就可以在1.10.0版本中使用(将在12月初发布)。