V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
justrun
V2EX  ›  问与答

Node https get 请求超时

  •  
  •   justrun · 2016-11-01 23:55:30 +08:00 · 524 次点击
    这是一个创建于 2733 天前的主题,其中的信息可能已经有所发展或是发生改变。

    测试 google cse 的 api ,在 chrome 和 postman 中都能在 1s 左右获取到返回的 json (网络畅通,未科学上网),可是在 Node 中使用 https 的代码请求就一直是超时状态,请问下有可能哪里出了问题?新人不太懂,谢谢!

    Node 中的代码, key 和 id 替换掉了:

    var options = {
      hostname: 'www.googleapis.com',
      port: null,
      path: '/customsearch/v1?key=我的 key&cx=我的 id&num=10&q=python',
      method: 'GET'
    };
    
    var req = https.request(options, (res) => {
      console.log('statusCode:', res.statusCode);
      console.log('headers:', res.headers);
    
      res.on('data', (d) => {
        process.stdout.write(d);
      });
    });
    req.end();
    
    req.on('error', (e) => {
      console.error(e);
    });
    

    报错 log :

    { [Error: connect ETIMEDOUT 172.217.26.106:443]
      code: 'ETIMEDOUT',
      errno: 'ETIMEDOUT',
      syscall: 'connect',
      address: '172.217.26.106',
      port: 443 }
    
    2 条回复    2016-11-02 00:40:54 +08:00
    justrun
        1
    justrun  
    OP
       2016-11-02 00:24:16 +08:00
    写了几句 python 试了下也能正常得到响应数据。。
    xxxyyy
        2
    xxxyyy  
       2016-11-02 00:40:54 +08:00 via Android
    是否在 hosts 里绑定了 www.googleapis.com
    自己 ping 172.217.26.106 可以 ping 的通吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2665 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:55 · PVG 12:55 · LAX 21:55 · JFK 00:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.