【问题标题】:How to get raw response data from axios request?如何从 axios 请求中获取原始响应数据?
【发布时间】:2020-09-01 12:02:54
【问题描述】:

我正在向 API 发出请求,在该 API 中,他们使用私钥对响应正文进行签名,并在标头中将签名发送给我。我应该使用他们的公钥来验证带有原始响应正文的签名,但是在 axios 解析响应数据时,其中有一些东西正在发生变化,这使得签名无效。有没有办法用 axios 获取原始响应数据?

我正在做一个 post 请求,想要获取 axios 自动为我解析的 JSON 对象的字符串。

【问题讨论】:

    标签: node.js axios


    【解决方案1】:

    您可以设置一个“身份”transformResponse。

    let res = axios.get("url",
    { transformResponse: (r) => r }); //null transform (we do not want to parse as JSON);
    
    //res.data should now contain a plain unparsed string
    

    不确定将 transformResponse 设置为 null 是否与身份转换相同。

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 2014-02-24
      • 2021-05-11
      • 2012-07-11
      • 1970-01-01
      相关资源
      最近更新 更多