【问题标题】:Nodejs Parse fetch response containing object [Symbol(map)]Nodejs Parse 获取包含对象 [Symbol(map)] 的响应
【发布时间】:2022-01-11 20:48:14
【问题描述】:

不知道如何访问参数x-error-detail-header。

我从使用 node-fetch npm 包的请求中收到此响应标头:

     Headers {
      [Symbol(map)]: 
  { 'content-type': [ 'text/xml' ],
 date: [ 'Fri, 27 Apr 2018 09:46:56 GMT' ],
 'retry-after': [ '51184' ],
 server: [ 'xxxxx' ],
 'x-error-detail-header': [ 'Account Over Rate Limit' ],
 'x-x-error-code': [ 'ERR_403_DEVELOPER_OVER_RATE' ],
 'x-x-responder': [ 'xxxxxxx.com' ],
 'x-plan-qps-allotted': [ '2' ],
 'x-plan-qps-current': [ '1' ],
 'x-plan-quota-allotted': [ '50' ],
 'x-plan-quota-current': [ '51' ],
 'x-plan-quota-reset': [ 'Saturday, April 28, 2018 12:00:00 AM GMT' ],
 'content-length': [ '28' ],
 connection: [ 'Close' ] } }

我的问题是我不知道如何访问 [Symbol(map)] 对象中的参数。

【问题讨论】:

    标签: javascript json node.js parsing fetch


    【解决方案1】:

    这是一个Headers object。它有例如getforEach 方法。例如:

    getDownload = async (url) => {
        const response = await fetch(url);
        console.log(response.headers.get('content-type'));
        return {
            name: response.headers.get('Content-Disposition'),
            length: response.headers.get('content-length')
        }
    }
    

    注意不区分大小写。

    【讨论】:

      猜你喜欢
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2020-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多