You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复使用Axios调用API时出现的400状态码请求错误

修复400请求错误的方案

核心问题:参数传递方式错误

aztro API要求POST请求的参数(sign和day)必须放在请求体中,而非URL查询参数里。你的代码把参数放在了params字段(对应URL拼接的查询参数),这是触发400错误的直接原因。

修复后的代码

const getZodicInfo = (sign, day) => {
  const options = {
    method: "POST",
    url: "https://sameer-kumar-aztro-v1.p.rapidapi.com/",
    // 将params替换为data,把参数放入请求体
    data: { sign: sign, day: day },
    headers: {
      "X-RapidAPI-Key": "edc6bd0575msh7fb7aa8058de303p15ffd6jsn551bf87a46dd",
      "X-RapidAPI-Host": "sameer-kumar-aztro-v1.p.rapidapi.com",
    },
  };

  return axios
    .request(options)
    .then(function (response) {
      return response.data;
    })
    .catch(function (error) {
      console.error(error);
    });
};

额外验证项

  • 检查sign参数:必须是API支持的全小写星座名称,比如aries、taurus等,拼写错误会触发400。
  • 检查day参数:只能是today、tomorrow或yesterday三者之一,其他值会返回错误。
  • 确认RapidAPI Key状态:如果Key过期、额度耗尽或权限不足,也可能导致400类错误,可在RapidAPI控制台查看Key有效性。

内容的提问来源于stack exchange,提问作者sakshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 22:52:41