【问题标题】:SuperAgent -- Fetching only the headersSuperAgent -- 仅获取标题
【发布时间】:2018-05-09 19:54:34
【问题描述】:

我正在使用来自 Node 的superagent

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

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

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

【问题讨论】:

标签: http get http-headers superagent


【解决方案1】:

感谢@CBroe 将我指向the right direction

对于未来的访客 ...

您需要将GET 请求替换为HEAD 请求。
例如,在我的情况下,它将是:

const request = require('superagent');

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多