首页 > 解决方案 > SuperAgent -- 仅获取标题

问题描述

我正在使用来自Node.js的超级代理。

对于这样一个简单的请求,我怎样才能只获取/请求页面的标题,而不是完整的内容?

request.get('https://google.com') .then((res) => {console.log(res.headers);}) .catch(err=> console.log(err.status));

我试图在文档和谷歌中找到,但找不到任何东西。

标签: httpgethttp-headerssuperagent

解决方案


感谢@CBroe 为我指明了正确的方向

对于来自未来的游客......

您需要用请求替换GET请求HEAD
例如,就我而言,它将是:

const request = require('superagent');

request
  .head('https://google.com')
  .then((res) => {console.log(res.headers);})
  .catch(err=> console.log(err.status));


推荐阅读