【发布时间】:2018-12-28 16:35:51
【问题描述】:
我想在已部署在虚拟机中的代理中创建 IoT 实体。目前我已经通过 curls 进行了交流,并且可以正常工作。
咨询“卷曲”:
(curl http://192.168.56.103:8080/ngsi10/updateContext -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
{
"contextElements": [{
"entityId": {
"id": "01",
"type": "example"
},
"attributes": [{
"name": "numbers",
"type": "int",
"contextValue": 24
}],
"domainMetadata": [{
"name": "location",
"type": "point",
"value": {
"latitude": 37.982636,
"longitude": -1.123510
}
}]
}],
"updateAction": "UPDATE"
}
EOF
这对我来说工作正常。
这是nodejs使用axios的等效代码:
var config = {
headers: {'Content-Type': 'application/json',
'Accept': 'application/json'}
};
var dataJSon = [{
"contextElements": [{
"entityId": {
"id": "01",
"type": "example"
},
"attributes": [{
"name": "numbers",
"type": "int",
"contextValue": 24
}],
"domainMetadata": [{
"name": "location",
"type": "point",
"value": {
"latitude": 37.982636,
"longitude": -1.123510
}
}]
}],
"updateAction": "UPDATE"
}];
const payload = {
topic: 'topic',
logs: dataJSon,
};
axios.get('http://192.168.56.103:8080/ngsi10/updateContext', dataJSon, config)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
执行最后一个时,代理告诉我他不明白,我已经用wireshark 发出了请求,但他做得不好,数据没有出现,我只看到一个标题。 Los contenidos de los datos 儿子 JSON。
我会把它放在这里以防有人帮我。非常感谢您。
【问题讨论】: