Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点js请求外部https url极慢_Node.js_Https - Fatal编程技术网

Node.js 节点js请求外部https url极慢

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

我使用https.request方法调用远程api,使用agentkeepalive, 不过还是很慢。 keep-alive代理将利用未使用的代理,但是,如果第一次调用或套接字已关闭,它仍然非常慢。 有什么问题吗

   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.