firebase - 从 Firebase Cloud 函数调用 Soap 服务错误
问题描述
我想从我的 firebase 云函数中调用一个肥皂服务 url
但是,从我的云函数调用它会给我以下错误。
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);
为什么?
解决方案
您应该使用完整的 URL,而不是部分 URL。它可能以https://
. 由于您没有使用它,因此您使用的 HTTP 库假定为 localhost (127.0.0.1),这显然无法正常工作。
推荐阅读
- python - Peewee ORM:如何在列值中获取()?
- html - Chrome url bar 与 100vh 与 css
- javascript - 从 Bootstrap 导航栏切换外观后选择搜索框
- material-ui - 带标签的图标按钮
- flutter - FlutterWeb - 显示目录中的所有图像
- bash - Bash sed 与贪婪的正则表达式
- sql - 如何在 PostgreSQL 中加入两个“未命名的表/选择”?
- jenkins - 启动和停止作业的功能
- javascript - Angular 没有“访问控制允许来源”
- javascript - 从音频 Web API 读取频率数据