https.request does not send body if it is the method DELETE

1

I am making a request to make a DELETE , and I have a problem, when ordering, bodyParams is not passed.

Has anyone ever had a similar problem? On the other hand I'm using the expression req.body and req.query .

Next is part of the function. The strange thing is that by doing POST , it works:

function request({
  options,
  method,
  resource,
  queryParams,
  bodyParams,
}) {
  return new Promise((resolve, reject) => {

    const stringifyedQueryParams = strigifyQueryParams(queryParams);

    const optionsRequest = {
      ...options,
      method,
      path: '${resource}${stringifyedQueryParams}',
    };

    const req = https.request(optionsRequest, (res) => {
      res.setEncoding(configs.ENCODING);
      res.on(events.DATA, data => resolve({
        body: data,
        statusCode: res.statusCode,
      }));
    });

    req.on(events.ERROR, error => reject(error) );
    req.write(JSON.strigify(bodyParams));
    req.end();
  });
}
    
asked by anonymous 27.12.2018 / 15:14

1 answer

1

By specification, the request DELETE has no defined semantics for body . That's probably why it's being ignored.

    
27.12.2018 / 19:23