search

Home  >  Q&A  >  body text

node.js - node request 响应慢(curl) 有什么好的解决方案呢

    // https://github.com/request/request
    
    const request = require('request')
    console.time('get')
    request.get('http://10.255.255.1', function(err) {
        console.timeEnd('get')
    });

平均在50ms左右 用curl命令 在 10以内

天蓬老师天蓬老师2787 days ago372

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 15:50:27

    Don’t use the request library, try sending requests directly using the http library that comes with node.

    var options = {
      hostname: '10.255.255.1',
      port: 80,
      path: '/',
      method: 'GET'
    };
    
    console.time('get');
    
    var req = http.request(options, (res) => {
      res.on('end', () => {
        console.timeEnd('get');
      });
    });

    request is an encapsulation of http

    reply
    0
  • Cancelreply