Fork me on GitHub

nodejs发送请求

const https = require('https');

var options = {
  hostname: 'registry.yarnpkg.com',
  port: 443,
  path: '/',
  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);
});
posted @ 2016-11-04 10:39  _落雨  阅读(1630)  评论(0编辑  收藏  举报