我正在尝试通过HTTPS进行SOAP调用。通常,我是通过Azure来执行此操作的,但工作正常,但是我正在开发一个新模块,需要通过我们的公司代理在本地调用它。如果我只是正常拨打电话,则会收到SELF_SIGNED_CERTIFICATE_IN_CHAIN
错误消息。在某些情况下,我可以使用https-proxy-agent
模块来解决此问题,但是当我按如下所示进行设置时,我收到了错误消息getaddrinfo ENOTFOUND undefined undefined:80
。我确定代理URL有效。在调试该调用时,我可以看到代理信息正在传递给该调用(通过easy-soap-request
启动SOAP调用,这又通过axios
进行了HTTP调用)。以下是一些相关的代码片段:
const soapRequest = require('easy-soap-request');
let httpsProxyAgent = require('https-proxy-agent');
var agent = new httpsProxyAgent({hostname:'proxy.address.com', port:8080, rejectUnauthorized:false});
// Next lines are within the class of my helper function
await (async () => {
var response = {};
try {
console.log('Converting catalog number...');
console.log(url);
response = await soapRequest(url, headers, requestXML, 10000, {httpsAgent:agent});
} catch (err) {
console.log(`Error converting catalog number: ${err}`);
processObj.message = 'SERVICE_DOWN';
processObj.error = err.message;
return;
}
// Then do some more stuff with the response, but I don't get this far
easy-soap-request模块本身似乎并没有做很多事情。让我想知道为什么我不只是发表request-promise-native
(我用于所有其他API调用)的帖子,但我想这是重点。这是easy-soap-request模块供参考。我唯一注意到的是它实际上是在使用axios-https-proxy-fix
而不是axios
。
const axios = require('axios-https-proxy-fix');
module.exports = function soapRequest(url, headers, xml, timeout = 10000, proxy = false) {
return new Promise((resolve, reject) => {
axios({
method: 'post',
url,
headers,
data: xml,
timeout,
proxy,
}).then((response) => {
resolve({
response: {
headers: response.headers,
body: response.data,
statusCode: response.status,
},
});
}).catch((error) => {
if (error.response) {
console.error(`SOAP FAIL: ${error}`);
reject(error.response.data);
} else {
console.error(`SOAP FAIL: ${error}`);
reject(error);
}
});
});
};
似乎我对easy-soap-request
并未真正增加太多价值的评论被证明是正确的。我很容易使用request-promise-native
作为替代产品。并且由于后者尊重我的.env代理变量,因此我也不需要使用httpsAgent。我仍然必须在选项中添加rejectUnauthorized:false
。这是更新后的代码,其中原始行已被注释掉:
//const soapRequest = require('easy-soap-request');
//let httpsProxyAgent = require('https-proxy-agent');
//var agent = new httpsProxyAgent({hostname:'proxy.address.com', port:8080, rejectUnauthorized:false});
const request = require('request-promise-native');
// Next lines are within the class of my helper function
await (async () => {
var response = {};
try {
console.log('Converting catalog number...');
console.log(url);
//response = await soapRequest(url, headers, requestXML, 10000, {httpsAgent:agent});
response = await request({
url: url,
method: 'POST',
headers: headers,
body: requestXML,
rejectUnauthorized: false
})
} catch (err) {
console.log(`Error converting catalog number: ${err}`);
processObj.message = 'SERVICE_DOWN';
processObj.error = err.message;
return;
}
像魅力一样运作!实际上,我将返回并更新其他集成模块以使用此方法,而不是在整个应用程序中使用easy-soap-request
。