Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.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 节点请求库:设置读取超时_Node.js_Request_Timeout - Fatal编程技术网

Node.js 节点请求库:设置读取超时

Node.js 节点请求库:设置读取超时,node.js,request,timeout,Node.js,Request,Timeout,我有一个响应速度很快的服务器,但随后必须从外部源获取数据。我相信这会导致读取超时 getSubdeviceStatus(){ var parent = this; let fullUrl = this.baseUrl + this.getSubdeviceStatusEndpoint; console.log(fullUrl); console.log(this.authHeaders); console.log(this.className+ "

我有一个响应速度很快的服务器,但随后必须从外部源获取数据。我相信这会导致读取超时

    getSubdeviceStatus(){
    var parent = this;
    let fullUrl = this.baseUrl + this.getSubdeviceStatusEndpoint;
    console.log(fullUrl);
    console.log(this.authHeaders);
    console.log(this.className+ ": getSubdeviceStatus called on Device: "+this.deviceGuid);
    request.get({
        headers: this.authHeaders,
        url:     fullUrl,
        timeout: 300000,
    }, function(error, response, body){
        console.log(response.statusCode);
        if (!error && response.statusCode == 200) {
            console.log("Response for "+fullUrl);
            console.log(response.headers)
            console.log(body.length);
            //parent.subdevices = [];
            let json_response = JSON.parse(body);
            //iterate through our updates
            }

        }else{
            console.log(this.className +": getSubdeviceStatus failed.")
            console.log(error);
        }
    });
}

如何手动设置读取超时?

嘿,John,你找到解决方案了吗?