Node.js 节点js请求外部https url极慢
我使用https.request方法调用远程api,使用agentkeepalive, 不过还是很慢。 keep-alive代理将利用未使用的代理,但是,如果第一次调用或套接字已关闭,它仍然非常慢。 有什么问题吗Node.js 节点js请求外部https url极慢,node.js,https,Node.js,Https,我使用https.request方法调用远程api,使用agentkeepalive, 不过还是很慢。 keep-alive代理将利用未使用的代理,但是,如果第一次调用或套接字已关闭,它仍然非常慢。 有什么问题吗 var HttpsAgent = require('agentkeepalive').HttpsAgent; var keepaliveAgent = new HttpsAgent({ maxSockets: 100, maxFreeSoc
var HttpsAgent = require('agentkeepalive').HttpsAgent;
var keepaliveAgent = new HttpsAgent({
maxSockets: 100,
maxFreeSockets: 10,
timeout: 60000,
keepAliveTimeout: 30000 // free socket keepalive for 30 seconds
});
var options = {
host: WECHAT_HOST,
path: WECHAT_PREPAY_URL,
method: "POST",
headers: {
"Content-Type": "application/xml",
"Content-Length": requestXml.length
},
agent: keepaliveAgent
};
var request = require("https").request(options, function (res) {
res.on("data", function (chunk) {
....
});
res.on("end", function () {
...
});
});
request.on("error", function (err) {
...
});
//Logger.Write("Request ready");
//console.log(requestXml.toString("utf-8"));
request.write(requestXml);
//Logger.Write("Data sent");
request.end();//The problem is here, wait for about 12 seconds, if I invoke same request in firefox, the remote server response immediately.