NodeJS 为什么axios返回z_buf_error?

sd2nnvve  于 2022-12-18  发布在  Node.js
关注(0)|答案(1)|浏览(221)

我遇到axios返回错误的问题

cause: Error: unexpected end of file
      at BrotliDecoder.zlibOnError [as onerror] (node:zlib:189:17) {
    errno: -5,
    code: 'Z_BUF_ERROR'

我用了这个功能,我不明白为什么,虽然我已经尝试了相同的像一个月前

export async function getCredentials(req: Request, res: Response) {
  const { code } = req.query;

  const params = new URLSearchParams({
    client_id: process.env.CLIENT_ID as string,
    client_secret: process.env.CLIENT_SECRET as string,
    grant_type: "authorization_code",
    code: code as string,
    redirect_uri: "http://localhost:3000/api/callback",
  });

  const response = await axios.post(
    "https://discord.com/api/oauth2/token",
    params,
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    }
  );

  res.json(await response.data);
}

谢谢大家!

kb5ga3dv

kb5ga3dv1#

很抱歉给您带来不便,解决方案是接受编码

const response = await axios.post(
    "https://discord.com/api/oauth2/token",
    params,
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Accept-Encoding": "*",
      },
    }
  );

相关问题