当使用“Fiware-Service: 旅游指南”header 时,无法将属性值作为 JSON
Cannot get attribute value as JSON when `Fiware-Service: tourguide` header is used
我们正在测试如何在 Tourguide 应用程序 (https://github.com/Fiware/tutorials.TourGuide-App) 中获取属性值,它似乎无法正常工作。
如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide'
我们得到
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
但是如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide' --header 'Accept: text/plain'
我们得到期望值:
Elizalde
我们试图强制 JSON 响应使用:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide' --header 'Accept: application/json'
但我们得到了同样的错误:
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
我们进行了一些额外的测试。
我们创建 Bcn-Welt 实体,如 https://github.com/telefonicaid/fiware-orion/blob/develop/doc/apiary/v2/fiware-ngsiv2-reference.apib#L922
中所述
如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/Bcn-Welt/attrs/humidity/value
我们得到了期望值。
但是,如果我们使用 Fiware-service: tourguide
header 创建实体并再次执行请求(使用 Fiware-Service: tourguide header
):
curl -v <cb_host>:<cb_port>/v2/Entities/Bcn-Welt/attrs/humidity/value -s -S --header 'Fiware-Service: tourguide'
我们得到:
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
有关使用的上下文代理版本的信息
{
"orion" : {
"version" : "1.1.0-next",
"uptime" : "0 d, 2 h, 16 m, 2 s",
"git_hash" : "2397fd46be54008409e7b2e4d29e572a2c598f2c",
"compile_time" : "Tue May 24 10:38:00 UTC 2016",
"compiled_by" : "root",
"compiled_in" : "838a42ae8431"
}
}
来自NGSIv2 specification,在GET属性值操作(GET /v2/entities/entityId/attrs/attrName/value
):
If response payload MIME type is application/json:
- ...
- If attribute value is a string, number, null or boolean, a HTTP error "406 Not Acceptable: accepted MIME types: text/plain" is returned.
看来行为符合预期。
旁注:您不应在 URL 中使用 /v2/Entities/...
,而应使用 NGSIv2 规范中定义的 /v2/entities
(小写 'E')。
我们正在测试如何在 Tourguide 应用程序 (https://github.com/Fiware/tutorials.TourGuide-App) 中获取属性值,它似乎无法正常工作。
如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide'
我们得到
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
但是如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide' --header 'Accept: text/plain'
我们得到期望值:
Elizalde
我们试图强制 JSON 响应使用:
curl -v <cb_host>:<cb_port>/v2/Entities/0115206c51f60b48b77e4c937835795c33bb953f/attrs/name/value -s -S --header 'Fiware-Service: tourguide' --header 'Accept: application/json'
但我们得到了同样的错误:
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
我们进行了一些额外的测试。
我们创建 Bcn-Welt 实体,如 https://github.com/telefonicaid/fiware-orion/blob/develop/doc/apiary/v2/fiware-ngsiv2-reference.apib#L922
中所述如果我们执行:
curl -v <cb_host>:<cb_port>/v2/Entities/Bcn-Welt/attrs/humidity/value
我们得到了期望值。
但是,如果我们使用 Fiware-service: tourguide
header 创建实体并再次执行请求(使用 Fiware-Service: tourguide header
):
curl -v <cb_host>:<cb_port>/v2/Entities/Bcn-Welt/attrs/humidity/value -s -S --header 'Fiware-Service: tourguide'
我们得到:
{"error":"NotAcceptable","description":"accepted MIME types: text/plain"}
有关使用的上下文代理版本的信息
{
"orion" : {
"version" : "1.1.0-next",
"uptime" : "0 d, 2 h, 16 m, 2 s",
"git_hash" : "2397fd46be54008409e7b2e4d29e572a2c598f2c",
"compile_time" : "Tue May 24 10:38:00 UTC 2016",
"compiled_by" : "root",
"compiled_in" : "838a42ae8431"
}
}
来自NGSIv2 specification,在GET属性值操作(GET /v2/entities/entityId/attrs/attrName/value
):
If response payload MIME type is application/json:
- ...
- If attribute value is a string, number, null or boolean, a HTTP error "406 Not Acceptable: accepted MIME types: text/plain" is returned.
看来行为符合预期。
旁注:您不应在 URL 中使用 /v2/Entities/...
,而应使用 NGSIv2 规范中定义的 /v2/entities
(小写 'E')。