代码之家  ›  专栏  ›  技术社区  ›  sisanared

javascript只调用头文件[重复]

  •  0
  • sisanared  · 技术社区  · 7 年前

    这个问题已经有了答案:

    如何在JS中调用以仅获取远程资产的头详细信息?我想在决定使用之前检查一下图像的大小

    我在找一个JS等价物:

    curl -s --head 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png'
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Quentin    7 年前

    首先,选择一个HTTP客户端库。然后使用head方法。

    例如

    const head_request_promise = axios({
      method: 'head',
      url: '/user/12345',
    });
    
        2
  •  0
  •   Ahm.    7 年前

    有人问这个问题 here

    如果你想用 request :

    var request = require('request');
    
    request("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png", {method: 'HEAD'}, function (err, res, body){
      console.log(res.headers);
    });
    

    如果你想用 node-fetch :

    const fetch = require('node-fetch');
    
    fetch('https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png')
    .then(res => console.log(res.headers.raw()))
    
    推荐文章