我正在编写需要与服务器通信的node.js应用程序。它建立与下面的代码HTTP连接:如何在node.js中为客户端http连接设置超时
var client = http.createClient(u.port, u.hostname, u.secure);
client.on("error", function(exception) {
logger.error("error from client");
});
var request = client.request(method, u.path, headers);
我没有看到node.js的文档中的任何选项的连接设置超时,它似乎被设置为20秒默认。我遇到的问题是,我在中国有用户,看起来是一个缓慢或片状的网络,有时候他们连接到我们美国的数据中心。我想将超时时间增加到1分钟,以查看是否为他们修复了这个问题。
有没有办法做到这一点在node.js?
正确的答案都在这个重复的问题:http://stackoverflow.com/questions/6214902/how-to-set-a-timeout-on-a-http-request-in-node(尤其是看杜威的回答) – Sandman4 2013-03-05 10:51:57
[如何在节点中设置http.request()的超时值?](https://stackoverflow.com/questions/6214902/how-to-set-a-timeout-on-a- http-request-in-node) – 2018-01-02 22:09:03