Reputation: 1262
I am trying to connect to SOAP server from Node.js using a HTTP request. It is however producing a ECONNRESET
error more or less straight away. I believe this is to do with timeout but cannot seem to fix it. I can't seem to figure out what the problem is. The port, host and path are all correct.
My HTTP request is:
var postRequest = {
host : "t1.webservice.secure.ddts.defra.gov.uk",
path: "/defraDataTransferPublicNWSE.asmx",
SOAPAction: "http://www.defra.gov.uk/TransferData",
port: 443,
method: "POST",
headers: {
'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': Buffer.byteLength(body2)
}
};
var buffer = "";
var req = http.request( postRequest, function( res ) {
console.log( res.statusCode );
var buffer = "";
res.on( "data", function( data ) { buffer = buffer + data; } );
res.on( "end", function( data ) { console.log( buffer ); } );
});
req.on('error', function(err) {
console.log( "----ERROR----" ); console.log(err);
});
req.write( body2 );
req.end();
Upvotes: 1
Views: 1782
Reputation: 29172
First, you must use https
module vs http
module.
The next problem with the certificate of authorization center.
Simple, you can set rejectUnauthorized
option to false
, but this is not very good.
The best option:
Symantec Class 3
Secure Server CA - G4
) from this page ssl-root-cas
*
var sslRootCAs = require('ssl-root-cas/latest')
.inject()`
.addFile( __dirname + '/Symantec Class 3 Secure Server CA - G4.cer' );
Upvotes: 3