发送RESTClient Firefox POST并在node.js中尝试相同的操作

我用FireFoxrest客户端发送以下post:

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> 

它的工作原理,我收到服务器的响应。

在Wireshark对话中,我看到RESTClient首先发送以下stream:

 ...........fe....0..S.... ..L0g....!...zP _....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......... 

然后我尝试使用node.js来做同样的事情。 HTTP客户端发送相同的post,我没有收到服务器的响应。 看着Wireshark对话,我看到第一个HTTP Clientstream的格式与firefox的RESTClient不同。

 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> 

这里的node.js脚本:

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

我做错了什么? 为什么Firefox发送不同于node.js HTTP Client的POST格式,以及那种格式?

提前致谢。

除了“保持活着”的“连接”标题和“内容types”之外,一切似乎都很好,正如@mithunsatheesh在其他问题中提到的那样, 如何在node.js http.request中发布XML数据,但我想你是已经意识到,因为代码是非常相似的两种情况下:)