我正在开发一个脚本,以向Fiware的Orion Context Broker发出POST请求。问题是a收到错误:
“ ContextLengthRequired”
,但请求中有Context-Length
标头。
这是我尝试节点fiware.js时的错误
{
"error":"ContentLengthRequired",
"description":"Zero/No Content-Length in PUT/POST/PATCH request"
}
这是文件 fiware.js 中的代码:
var request = require('request');
var entity = {
"id": "Room6",
"type": "Room",
"temperature": {
"value": 23,
"type": "Float"
},
"pressure": {
"value": 700,
"type": "Float"
}
};
var jsonObject = JSON.stringify(entity);
var aux = jsonObject.toString();
aux = aux.length;
var peticion = {
url: "http://127.0.0.1:1026/v2/entities",
method: "POST",
headers: {
"Content-Length": aux,
"Content-Type": "application/json"
},
data: jsonObject
};
request(peticion, function(error, response, body) {
console.log(error);
console.log(body);
});
答案 0 :(得分:0)
从此更改变量peticion:
var peticion = { 网址:“ http://127.0.0.1:1026/v2/entities”, 方法:“ POST”, 标头:{ “内容长度”:辅助, “ Content-Type”:“ application / json” }, 数据:jsonObject };
对此:
var peticion = { 网址:“ http://127.0.0.1:1026/v2/entities”, 方法:“ POST”, 标头:{ “内容长度”:辅助, “ Content-Type”:“ application / json” }, body :jsonObject };