2

I'm sending the following post with FireFox rest client:

POST /WSPublic.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 462
Host: host
Connection: close

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><ContadoresTR xmlns="https://xxxxx"><Usuario>user</Usuario><Contrasena>password</Contrasena><NInstalacion>inst</NInstalacion><VersionFicheroEsperado>1</VersionFicheroEsperado></ContadoresTR></soap12:Body></soap12:Envelope>

It works, and I receive the response from the server.

Looking in Wireshark conversations, I see that firstly the RESTClient sends the following stream:

...........fe....0..S.... ..L0g....!...z.P. _....N.im3....8.q.'...6.9.....p>. .+./.
...........3.2.9./.5.
.......c........
ges.leako.com......
.................#..3t.....!...h2-14.spdy/3.1.spdy/3.http/1.1......... 

Then I try to do the same using node.js. The HTTP client sends the same post and I don't receive response from the server. Looking at the Wireshark conversations, I see that the first HTTP Client stream the format is different from the RESTClient of firefox.

POST /WSPublic.asmx HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 462
Host: host
Connection: close

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><ContadoresTR xmlns="https://xxxxxx"><Usuario>user</Usuario><Contrasena>password</Contrasena><NInstalacion>inst</NInstalacion><VersionFicheroEsperado>1</VersionFicheroEsperado></ContadoresTR></soap12:Body></soap12:Envelope>

Here the node.js script:

var http = require("http")

var body = '<?xml version="1.0" encoding="utf-8"?>'
            +'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' 
                     +'xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
                     +'xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'
                +'<soap12:Body>'
                    +'<ContadoresTR xmlns="https://ges.leako.com/WSPublic">'
                        +'<Usuario>xxx</Usuario>'
                        +'<Contrasena>xxx</Contrasena>'
                        +'<NInstalacion>xxx</NInstalacion>'
                        +'<VersionFicheroEsperado>x</VersionFicheroEsperado>'
                    +'</ContadoresTR>'
                +'</soap12:Body>'
            +'</soap12:Envelope>';

var postRequest = {
    host: "ges.leako.com",
    path: "/WSPublic.asmx",
    port: 443,
    method: "POST",
    headers: {
        'Content-Type': 'application/soap+xml; charset=utf-8',
        'Content-Length': Buffer.byteLength(body),
    'Connection': 'keep-alive'
    }
};

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.write( body );
req.end();

What I'm doing wrong? Why Firefox send the POST format different than the node.js HTTP Client, and which is that format?

Thanks in advance.

JosepB
  • 2,205
  • 4
  • 20
  • 40

1 Answers1

0

Apart from the 'keep-alive' 'Connection' header and the 'Content-type' one, everything seems fine as mentioned by @mithunsatheesh in this other question how to post XML data in node.js http.request but I guess you were already aware of that since the code is pretty similar in both cases :)

Community
  • 1
  • 1