Ошибка при попытке сделать POST-запрос в Fiware - PullRequest
0 голосов
/ 25 марта 2019

Я разрабатываю скрипт для выполнения запроса POST к Orion Context Broker из Fiware. Проблема в том, что получаю ошибку:

"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);
});

1 Ответ

0 голосов
/ 03 апреля 2019

Измените переменную peticion из этого:

var peticion = { URL: "http://127.0.0.1:1026/v2/entities", метод: "ПОЧТА", заголовки: { «Content-Length»: aux, "Content-Type": "application / json" }, данные : jsonObject };

На этот:

var peticion = { URL: "http://127.0.0.1:1026/v2/entities", метод: "ПОЧТА", заголовки: { «Content-Length»: aux, "Content-Type": "application / json" }, body : jsonObject }; * 1 018 *

...