Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在发送RESTClient Firefox POST,并在node.js中尝试相同的操作_Node.js_Firefox_Httpclient_Rest Client - Fatal编程技术网

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

正在发送RESTClient Firefox POST,并在node.js中尝试相同的操作,node.js,firefox,httpclient,rest-client,Node.js,Firefox,Httpclient,Rest Client,我将通过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/

我将通过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>
然后我尝试使用node.js执行同样的操作。HTTP客户端发送相同的post,而我没有收到来自服务器的响应。查看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>
POST/WSPublic.asmx HTTP/1.1
内容类型:应用程序/soap+xml;字符集=utf-8
内容长度:462
主持人:主持人
连接:关闭
用户密码inst1
下面是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();
var http=require(“http”)
变量体=“”
+''
+''
+''
+“xxx”
+“xxx”
+“xxx”
+“x”
+''
+''
+'';
var postRequest={
主持人:“ges.leako.com”,
路径:“/WSPublic.asmx”,
港口:443,
方法:“张贴”,
标题:{
“内容类型”:“应用程序/soap+xml;字符集=utf-8”,
“内容长度”:缓冲区。字节长度(正文),
“连接”:“保持活动”
}
};
var buffer=“”;
var req=http.request(postRequest,函数(res){
console.log(res.statusCode);
var buffer=“”;
res.on(“data”,函数(data){buffer=buffer+data;});
res.on(“end”,函数(数据){console.log(buffer);});
});
请求写入(正文);
请求结束();
我做错了什么?为什么Firefox发送的POST格式与node.js HTTP客户端不同,是哪种格式


提前感谢。

除了“保持活动”连接头和“内容类型”头之外,正如@mithunsatheesh在另一个问题中提到的,一切似乎都很好,但我想您已经意识到了这一点,因为这两种情况下的代码非常相似:)

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