Getting HTTP headers with Node.js

后端 未结 6 2014
野的像风
野的像风 2020-11-29 02:36

Is there a built in way to get the headers of a specific address via node.js?

something like,

var headers = getUrlHeaders(\"http://stackoverflow.com\         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 03:11

    Using the excellent request module:

    var request = require('request');
      request("http://stackoverflow.com", {method: 'HEAD'}, function (err, res, body){
      console.log(res.headers);
    });
    

    You can change the method to GET if you wish, but using HEAD will save you from getting the entire response body if you only wish to look at the headers.

提交回复
热议问题