为node-soap提供http客户端

问题描述 投票:0回答:1

我正在尝试设置 maxSockets 的请求,并将此发送给 node-soap 创建客户端时。没有这个功能,交易也能正常进行。我试着通过httpAgent添加它,但是一旦有了 maxSockets 属性,我得到了一个 socket hang up 错误。所以,我现在的方法是尝试使用 httpClient 然而,我一直无法做到这一点。这是我的代码。

//OPTION 1
const httpsAgent = new https.Agent({ keepAlive: true });
const httpsClient: AxiosInstance = axios.create();
httpsClient.request({
  url: url,
  httpsAgent: httpsAgent,
  timeout: 15000,
});

//OPTION 2
const httpsAgent = new https.Agent({ keepAlive: true });
const httpsClient: AxiosInstance = axios.create();
httpsClient.defaults.httpsAgent = HttpsAgent;

这是库的文档中关于httpClient的说明。httpClient: to provide your own http client that implements request(url, data, callback, exheaders, exoptions).

node.js http soap httpclient node-soap
1个回答
0
投票

发现在请求中设置 keepAlive 属性的HTTP代理杀死了连接。所以我只设置了 maxSockets 并在其上添加一个头 node-soap 创建客户端时。

client.addHttpHeader("connection", "keep-alive");

© www.soinside.com 2019 - 2024. All rights reserved.