I am writing a Node JS SOAP client using Node-Soap module to send a file to a remote SharePoint based Web Services.
The machine client requires a proxy to access Internet and the SharePoint WS requires an account (user, pwd). Below are the code source.
However, I always have the error "(node:20857) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot parse response".
Someone can help me, please?
var process = require('process');
var fs = require('fs');
var request = require('request')
var soap = require('soap');
var apiWSDL = '.../test-collab/WS/_vti_bin/copy.asmx?wsdl';
function sendFile() {
var p = new Promise(function (resolve, reject) {
request_with_defaults = request.defaults({
'proxy': 'http://***:***@10.115.108.109:8080',
'timeout': 50000,
'connection': 'keep-alive'
});
var options = {
'request': request_with_defaults,
endpoint: 'https://.../test-collab/WS/_vti_bin/copy.asmx',
}
var byteArray = fs.readFileSync('test.txt').toString('base64');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
//process.env.https_proxy = 'http://***@***:10.115.108.109:8080';
soap.createClient(apiWSDL, options, function (err, client) {
if (err) throw new Error(err);
var args = {
DestinationUrls: 'https://.../test-collab/WS/CAS/test.txt',
Stream: byteArray
}
client.setSecurity(new soap.ClientSSLSecurity(null, null, null, { /*default request options like */
strictSSL: false,
rejectUnauthorized: false,
// hostname: 'some-hostname'
//secureOptions: constants.SSL_OP_NO_TLSv1_2,
forever: true,
}));
client.addHttpHeader('vm6_webapp', 'SERVICE');
client.addHttpHeader('vm6_password', '***');
client.addHttpHeader('vm6_user', '***');
client.CopyIntoItems(args, function (err, result) {
//console.log(err);
if (err) {
console.log(err);
reject(err);
}
var sets;
try {
console.log(result);
if (result.length) {
resolve(result);
} else {
reject(result);
}
} catch (error) {
console.log("error");
reject("error und")
}
});
});
});
return p;
}