Axios请求失败,状态码为429,但它与Postman一起使用 [英] Axios Request failed with status code 429 but it is working with Postman

查看:1138
本文介绍了Axios请求失败,状态码为429,但它与Postman一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用axios访问此API,但出现错误 状态: 429 [请求过多] . 我只发送了一个仍然出错的请求.

I am trying to access this API using axios but I am getting error with status: 429 [ Too many Requests ]. I am sending only one requests still getting an error.

但是,当我尝试使用邮递员访问此URL时,它仍然有效.

BUT when I try to access this url using postman it is working.

axios
  .post(
    `https://www.expedia.com/Hotel-Search-Data?responsive=true&destination=New+York%2C+New+York&latLong=40.75668%2C-73.98647&regionId=178293&startDate=01%2F20%2F2019&endDate=01%2F21%2F2019&rooms=1&adults=2&timezoneOffset=19800000&langid=1033&hsrIdentifier=HSR&page=7`
  )
  .then(result => {
    console.log(result.data);
  })
  .catch(err => {
    console.log(err);
  });

推荐答案

我遇到了同样的问题,并且由于请求过多而发生这种情况.

I ran into this same issue and this happens because of too many requests.

您可能正在某个循环内运行上述行,这导致当Axios同时触发所有请求时发生这种情况.

You are probably running the above line inside some loop which is causing this to happen as Axios is firing off all requests simultaneously.

解决方法是等待,就像这样

try {
  const result = await axios.post(`YOUR_URL`, {<Your JSON payload>});
} catch (error) {
  console.error(error);
}

请注意,上面的代码必须位于异步函数中.

Please note the above code has to be inside an async function.

这篇关于Axios请求失败,状态码为429,但它与Postman一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆