我们对<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDwEvCr3alGTKBFt23yk4WVqduw4534CJs&libraries=places&callback=initMap"
async defer></script>
操作行为有疑问,如果我们使用/v2/entities/{entityId}/attrs/{attrName}/value
标头,Context Broker会尝试返回不支持的格式。
Accept: */*
我们需要明确接受curl -v orion:1026/v2/entities/Bcn-Welt/attrs/humidity/value
* Hostname was NOT found in DNS cache
* Trying 172.17.0.13...
* Connected to orion (172.17.0.13) port 1026 (#0)
> GET /v2/entities/Bcn-Welt/attrs/humidity/value HTTP/1.1
> User-Agent: curl/7.35.0
> Host: orion:1026
> Accept: */*
>
< HTTP/1.1 406 Not Acceptable
< Connection: Keep-Alive
< Content-Length: 73
< Content-Type: application/json
< Fiware-Correlator: d289fd9e-2329-11e6-88cc-0242ac11000d
< Date: Thu, 26 May 2016 10:08:41 GMT
<
* Connection #0 to host orion left intact
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
格式:
text/plain
如果我们提供了已接受格式的列表,甚至是不支持的格式(JSON除外),则应用程序将返回该值。
curl -v orion:1026/v2/entities/Bcn-Welt/attrs/humidity/value --header "Accept: text/plain"
* Hostname was NOT found in DNS cache
* Trying 172.17.0.13...
* Connected to orion (172.17.0.13) port 1026 (#0)
> GET /v2/entities/Bcn-Welt/attrs/humidity/value HTTP/1.1
> User-Agent: curl/7.35.0
> Host: orion:1026
> Accept: text/plain
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Length: 9
< Content-Type: text/plain
< Fiware-Correlator: 70b2a3f8-232b-11e6-a36a-0242ac11000d
< Date: Thu, 26 May 2016 10:20:16 GMT
<
* Connection #0 to host orion left intact
如果我们在接受列表中提供JSON格式,则请求失败:
curl -v orion:1026/v2/entities/Bcn-Welt/attrs/humidity/value --header "Accept: audio/*"
* Hostname was NOT found in DNS cache
* Trying 172.17.0.13...
* Connected to orion (172.17.0.13) port 1026 (#0)
> GET /v2/entities/Bcn-Welt/attrs/humidity/value HTTP/1.1
> User-Agent: curl/7.35.0
> Host: orion:1026
> Accept: audio/*
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Content-Length: 9
< Content-Type: text/plain
< Fiware-Correlator: a216e33c-232b-11e6-83f3-0242ac11000d
< Date: Thu, 26 May 2016 10:21:39 GMT
<
* Connection #0 to host orion left intact
60.000000
答案 0 :(得分:1)
逐案:
在第一种情况下,正在发生的事情是Orion(在版本1.1和之前)第一个选择MIME类型,然后会考虑属性类型是否适合它。使用Accept: */*
,application / json和text / plain之间存在联系,Orion选择application / json作为获胜者。然后,假定属性的值是文本性质,则返回错误。
第二种情况可能是一个错误。我们已经创建了an issue at github。
第三种情况与第一种情况类似。 text / plain和application / json之间有一个联系。猎户座选择了第二个。然后,当它评估属性值时,它意识到它与application / json MIME类型不匹配并返回错误。
事实上,在案例1或3中实施的程序并不是最好的。在在Accept
标头中的所有可能选项中选择MIME类型之前,应该评估属性类型。我的意思是,要实现所描述的here:
如果属性值是数组或对象,并且Accept标头包含application / json或text / plain:将值作为JSON返回,其响应类型为application / json或text / plain(以第一个为准)接受标题)。
如果属性值是字符串,数字,null或布尔值:
- 如果Accept标头包含text / plain,则返回值为text
- else返回HTTP错误“406 Not Acceptable:accepted MIME types:text / plain”
该程序将在下一版本的Orion中实施。
编辑:新程序已在Orion 1.3.0中实施。