Skip to Content
May 02, 2018 at 01:50 PM

Problemas al conectar Service Layer en JavaScript / Problems to connect Service Layer in JavaScript

1313 Views Last edit May 02, 2018 at 03:01 PM 3 rev

Estoy realizando un conector a ServiceLayer en JavaScript con Node.js y Express. Cuando intenta hacer la conexión se queda un rato esperando respuesta y da el error “SOCKET HANG UP”. Si realizo la misma conexión a través del POSTMAN me funciona correctamente.

He comprobado la configuración del Service Layer según se indicaba en otros blogs. También he buscado por foros y tras probar las distintas soluciones me sigue dando el mismo error.

Adjunto como realizo la conexión:

I’m developing a connector to ServiceLayer in JavaScript with Node.js and Express. When it tries to make the connection it waits for a while waiting for an answer and it gives the error “SOCKET HANG UP”. If I make the same connection through POSTMAN, it works correctly.

I have checked the configuration of the Service Layer as indicated in other blogs. I have also searched through forums and after trying the different solutions I still get the same error.

I attach how I made the connection:

var https = require(‘https‘);

var connected = false;

var SessionID;

var SLServer;

exports.connectSL = function(re, res){




var post_req = null,

post_data = re;

var post_options = {

hostname: ‘’,

port : ‘50000’,

path : ‘b1s/v1/Login’,

method : ‘POST’,

body : post_data,

json : true,

headers : {

‘Content-Type’: ‘application/json‘,

‘Cache-Control’: ‘no-cache’,

‘Content-Length’: post_data.length


rejectUnauthorized: false,

requestCert: true,

agent: false


console.log(‘Realizando conexion‘);


post_req = https.request(post_options, function (res) {

console.log(‘STATUS: ‘ + res.statusCode);

console.log(‘HEADERS: ‘ + JSON.stringify(res.headers));


res.on(‘data’, function (chunk) {

console.log(‘Response: ‘, chunk);



post_req.on(‘error’, function(e) {

console.log(‘problem with request: ‘ + e.message);