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

为什么日期变更后调用API查询数据会返回400错误码?

问题原因
  • 核心错误:拼接to日期参数时写死了当月最后一天为31号,但9月只有30天,不存在「年+09+31」的合法日期,接口校验参数不通过返回400。8月有31天,参数合法所以可以正常请求。
  • 潜在错误:拼接日期时固定加前缀0,当月份≥10时,0${month}会得到010/011/012,最终生成202X01001这类非法日期格式,后续10-12月也会触发400错误。
  • 若实际代码中参数分隔符写的是&而非普通&,也会导致接口无法正确解析多个参数,触发参数错误。
修复代码
const date = new Date();
const year = date.getFullYear();
// 月份补两位零
const month = (date.getMonth() + 1).toString().padStart(2, '0');
// 动态计算当月最后一天
const lastDay = new Date(year, date.getMonth() + 1, 0).getDate().toString().padStart(2, '0');
// 拼接路径时使用普通&作为参数分隔符
const path =  `/v2/reports/time/team?from=${year}${month}01&to=${year}${month}${lastDay}`;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 08:48:04