I am trying to create a script to login into a SOAP API service and am running an issue with the Buffer function.
The example that were provided to me use the following header for the https.request command:
headers: {
“Content-Type”: “text/xml; charset=utf-8”,
“Content-Length”: Buffer.byteLength(SOAPbodyVariable),
Authorization: "Basic " + new Buffer(username + “:” + password).toString(“base64”),
SOAPAction: “http://webserviceURL”,
Accept: “application/json”
}
This basically stops my script from working. If i comment out or delete:
“Content-Length”: Buffer.byteLength(SOAPbodyVariable),
Authorization: "Basic " + new Buffer(username + “:” + password).toString(“base64”),
the script works again.
I am not sure if i am missing somehting, but it seems that i am hung on anything that has to do with “Buffer”.
Generally my attempt to create a soap call is:
function APIcall(SOAPbodyVariable) {
var cred = getcreds();
var url = ‘https://webservicesurl’;
var options = {
host: url,
port: 443,
method: “POST”,
path: cred.asmxpath,
headers: {
“Content-Type”: “text/xml; charset=utf-8”,
“Content-Length”: Buffer.byteLength(SOAPbodyVariable),
Authorization: "Basic " + " new Buffer(cred.username + “:” + cred.password).toString(“base64”),
SOAPAction: “http:/soapURL/action”,
Accept: “application/json”
}
};
request = https.request(options, function (res) {
console.log(“statusCode:”, res.statusCode);
res.on(“data”, (d) => { log process.stdout.write(d); });
});
request.on(“error”, (e) => { console.error(e); });
request.end(xml);
return request;
}
Because i can not get the Buffer issue resolved i don’t even know if the actual request actually works and whether i am returning the results properly.
Thank you for any assistance
CE