Node.js http请求超时错误

时间:2018-01-02 07:47:20

标签: node.js npm request

我正在使用npm请求模块来调用http api。它适用于1个网址但不适用于同一个域名的其他网址,每次我都会超时。同样的网址正在邮递员工作。可能是什么原因?

 var request = require("request");
    const url1 = 'http://example.com/xyz';
    const url2 = 'http://example.com/jkl';
    var options = {
        method: 'GET',
        url: url,
        headers: {
            Host: 'example.com',
            'User-Agent': 'request'
        }
    };

    request(options, function(error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });

1 个答案:

答案 0 :(得分:0)

要处理超时问题,您可以选择以下方式:

void onClickCallback(int event, int x, int y, int, void*);

int main(int argc, char **argv) {

    Mat image = imread("/home/zda/0.png", CV_LOAD_IMAGE_COLOR);

    namedWindow("image");
    setMouseCallback( "image", onClickCallback, &image);

    imshow("image",image);
    while ('q' != waitKey(0));
}

void onClickCallback( int event, int x, int y, int, void *image) {
    if(event == CV_EVENT_LBUTTONDOWN) {
        std::cout << "value at (" << x << ", " << y << ") is " << ((Mat*)image)->at<Vec3b>(y, x) << endl;
        //This one for grayscale
        //std::cout << "value at (" << x << ", " << y << ") is " << (int)((Mat*)image)->at<uchar>(y, x) << endl;

    }
}