简体   繁体   中英

Connecting to SOAP server from Node.js producing ECONNRESET error

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();

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:

  • Download Symantec Intermediate CA (ICA) Certificate ( Symantec Class 3 Secure Server CA - G4 ) from this page
  • install module ssl-root-cas
  • add certificate before request:

*

var sslRootCAs = require('ssl-root-cas/latest')
    .inject()`
    .addFile( __dirname + '/Symantec Class 3 Secure Server CA - G4.cer' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM