【问题标题】:Messed data object in response with Axios混乱的数据对象响应 Axios
【发布时间】:2022-12-20 04:56:50
【问题描述】:

我正在请求获取 auth0 API 的 access_token。 请求成功,但包含访问令牌的数据对象包含奇怪的字符。问题是我拥有那个物品 3-4 个小时,之后就再也没有找回过它。有什么线索吗?

这是代码:

(async () => {
  const client = axios.create({
    baseURL: 'https://my_url_to.auth0.com/oauth/token',
    headers: {
      'Content-Type': 'application/json'
    }
  });

  Log.debug(body);

  try {
    const resp = await client.post('/', body);

    console.log(JSON.stringify(resp.data));
  } catch (e) {
    Log.error(e);
  }
})();

【问题讨论】:

    标签: axios


    【解决方案1】:

    在 v1.2.1 中修复了这个错误。

    您需要在 axios 标头中添加 Accept-Encoding 和 'application/json'。

    axios 默认是 gzip。

    此代码将有效

    (async () => {
      const client = axios.create({
        baseURL: 'https://my_url_to.auth0.com/oauth/token',
        headers: {
          'Content-Type': 'application/json',
          'Accept-Encoding': 'application/json'
        }
      });
    
      Log.debug(body);
    
      try {
        const resp = await client.post('/', body);
    
        console.log(JSON.stringify(resp.data));
      } catch (e) {
        Log.error(e);
      }
    })();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 2013-02-13
      • 2021-08-14
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多