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

查看:188
本文介绍了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.

但是当我尝试使用邮递员访问此网址时,它正在工作.

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.

解决方法是等待响应,类似这样

The workaround would be to await the response, something like this

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

请注意,上述代码必须位于 async 函数内.

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

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

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