【问题标题】:Provide httpClient to node-soap向 node-soap 提供 httpClient
【发布时间】:2020-04-29 03:07:46
【问题描述】:

我正在尝试在请求上设置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】:

    发现在 HTTP 代理上设置 keepAlive 属性正在终止连接。所以我只在上面设置了maxSockets,并在创建客户端时给node-soap添加了一个header。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 2017-11-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      相关资源
      最近更新 更多