The error can occur if you send an empty POST body. If you look at the nodejs docs you will see that there is no body option when creating the request object with https.request.
The correct way of setting the body in the request is to call the req.write method before calling req.end
var options = {
host: "api.sandbox.ebay.com",
path: '/ws/api.dll',
method: "POST",
headers: {
'X-EBAY-API-APP-NAME': 'my app id',
'X-EBAY-API-DEV-NAME': 'my dev id',
'X-EBAY-API-CERT-NAME': 'my cert id',
'X-EBAY-API-COMPATIBILITY-LEVEL': '557',
'X-EBAY-API-CALL-NAME': 'GetSessionID',
'X-EBAY-API-SITEID':'203',
'Content-Type' : 'text/xml',
'Content-Length':xml.length
}
};
var req = https.request(options, function (res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function (d) {
process.stdout.write(d);
});
});
req.on('error', function (e) {
console.error('error=======', e);
});
req.write(xml);
req.end();