代码之家  ›  专栏  ›  技术社区  ›  Ruan

从Firebase云函数调用Soap服务时出错

  •  0
  • Ruan  · 技术社区  · 7 年前

    我想从firebase云函数调用soap服务url

    1. 我可以在postman上调用这个soap函数,它可以工作。 enter image description here

    XMLHttpRequest错误:

    "Message": "Error: connect ECONNREFUSED 127.0.0.1:80\n    at Object.exports._errnoException (util.js:1020:11)\n    at exports._exceptionWithHostPort (util.js:1043:20)\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1105:14)"
    

    代码

      var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
            var xmlhttp = new XMLHttpRequest();
    
            //replace second argument with the path to your Secret Server webservices
            xmlhttp.open('POST', 'xxxxx/SiloFunctions.asmx');
    
            //create the SOAP request
            var sr =
                '<soapenv:Envelope ' +
                'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
                'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
                'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                '<soap:Body>' +
                '<Request xmlns="http://tempuri.org/">' +
                '<Password>xxxx</Password>' +
                '<Latitude>123</Latitude>' +
                '<Longitude>123</Longitude>' +
                '<ClientName>123</ClientName>' +
                '<ClientSurname>123</ClientSurname>' +
                '<MSISDN>123123</MSISDN>' +
                '</Request>' +
                '</soap:Body>' +
                '</soapenv:Envelope>';
    
    
            //specify request headers
            xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    
            //FOR TESTING: display results in an alert box once the response is received
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    res.status(200).send(
                        {
                            "Message": xmlhttp.responseText,
                        })
                }
            };
    
            //send the SOAP request
            xmlhttp.send(sr);
    

    为什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Doug Stevenson    7 年前

    您应该使用完整的URL,而不是部分URL。可能是从 https:// . 因为您没有使用它,所以您使用的HTTP库假设localhost(127.0.0.1),这显然是行不通的。