For some reason a third party API is accepting my request.post request but not my https.request one. The returned error from the latter is that the XML is invalid or malformed. I would prefer to use https and not request as it adds unnecessary overhead.
How can i debug the 2 functions so that I can match my https.request output to the request.post one?
request.post
request.post({url: 'https://api.example.com/post.php', form: { xml: full_xml_data }}, function(err, resp, xml){
  // request is successful
});
https.request
let options = {
  "hostname": api.example.com,
  "port": 443,
  "path": '/post.php',
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Content-Length": full_xml_data.length
  }
};
let req = https.request(options, (res) => {
  let xml="";
  res.on("data", function(data){ xml+=data; });
  res.on("end", function(){
    // request is not successful, respons from API is that xml is invalid/malformed
  });
});
req.on("error", (err) => {
  // error handler
});
let post_data = querystring.stringify({"xml":full_xml_data});
// i have also tried: let post_data = 'xml='+encodeURIComponent(full_xml_data);
req.write(post_data);
req.end();
Any ideas on how to resolve this would be much appreciated! Thomas
 
    