gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:36:07 26 4
gpt4 key购买 nike

我正在使用 FireFox Rest 客户端发送以下帖子:

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 首先发送以下流:

...........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.........

然后我尝试使用 node.js 执行相同的操作。 HTTP 客户端发送相同的帖子,但我没有收到服务器的响应。查看 Wireshark 对话,我发现第一个 HTTP 客户端流的格式与 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 发送的 POST 格式与 Node.js HTTP 客户端不同,该格式是什么?

提前致谢。

最佳答案

除了“keep-alive”“Connection” header 和“Content-type” header 之外,一切似乎都很好,正如 @mithunsatheesh 在另一问题 how to post XML data in node.js http.request 中提到的那样。但我想您已经意识到了这一点,因为这两种情况下的代码都非常相似:)

关于node.js - 发送 RESTClient Firefox POST 并在 node.js 中尝试相同的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28853130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com