简体   繁体   English

GET 请求通过 Axios 返回错误 404,但在 Postman 中有效?

[英]GET request returns Error 404 through Axios, but works in Postman?

I'm developing a mobile app using the GiantBomb API .我正在使用GiantBomb API开发移动应用程序。 I'm developing using React Native and Expo.我正在使用 React Native 和 Expo 进行开发。 I'm currently working on a screen in the app which takes the unique GUID of a game selected from a list and displays the relevant information.我目前正在应用程序中的一个屏幕上工作,该屏幕采用从列表中选择的游戏的唯一 GUID 并显示相关信息。 It gets the data it needs through an Axios GET request.它通过 Axios GET 请求获取所需的数据。

Earlier screens in the app retrieve different data from the API through the same method with no problems, and when putting the same request used in the app into Postman - using the same GUID - I get the data I expect returned.应用程序中的早期屏幕通过相同的方法从 API 检索不同的数据,没有问题,并且当将应用程序中使用的相同请求放入 Postman 时 - 使用相同的 GUID - 我得到了我期望返回的数据。

For some reason, the GET request made through Axios returns a 404 error while the same GET request made through Postman gives me the information I need.出于某种原因,通过 Axios 发出的 GET 请求返回 404 错误,而通过 Postman 发出的相同 GET 请求为我提供了我需要的信息。

This is the Axios request made in the app:这是在应用程序中发出的 Axios 请求:

    axios({
      url: "https://www.giantbomb.com/api/game/"+{gameId}+"/?api_key=[API_KEY]",
      method: 'GET',
    })
      .then(response => {
          setgameData(response.data);
      })
      .catch(err => {
          console.error(err);
      });
  }

I know that the screen that is meant to show the game data has the GUID, because it is displayed on the screen.我知道用于显示游戏数据的屏幕具有 GUID,因为它显示在屏幕上。 When the displayed GUID is entered into a Postman request, I get the data I expect.当显示的 GUID 输入到 Postman 请求中时,我得到了我期望的数据。

Why does this happen?为什么会这样? How can I fix it?我该如何解决?

EDIT: The following is the Axios response the app provides me:编辑:以下是应用程序为我提供的 Axios 响应:

- node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\axios\lib\core\settle.js:16:9 in settle
- node_modules\axios\lib\adapters\xhr.js:53:6 in handleLoad
- node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:592:4 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

3030-16836

Request failed with status code 404
- node_modules\axios\lib\core\createError.js:15:17 in createError
- node_modules\axios\lib\core\settle.js:16:9 in settle
- node_modules\axios\lib\adapters\xhr.js:53:6 in handleLoad
- node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:592:4 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

As commenters have pointed out (thanks @MinusFour @MasoudTahmasebi @spijs) the problem was a simple syntax mistake involving misplaced {}.正如评论者所指出的(感谢@MinusFour @MasoudTahmasebi @spijs),问题是一个简单的语法错误,涉及错位的{}。 Thanks all of you!感谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Axios GET 请求在 Postman 中工作但抛出 400 错误 - Redux - Axios GET Request works in Postman but throws 400 error - Redux redash GET 请求适用于 POSTMAN 但不适用于 axios - redash GET request works on POSTMAN but not on axios 邮递员请求有效,但 axios CORS 无效 - Postman request works but not axios CORS Axios 发布请求 React.js 时出现网络错误,但适用于 Postman - Axios Network error on post request React.js but works on Postman GET请求错误404(未找到)使用axios - GET request error 404 (not found) using axios 带有 POST 请求的 Express JS 路由在 Postman 中返回 404 无法 GET 错误 - Express JS route with POST request returns 404 Cannot GET error in Postman GET请求有效,但POST返回404 - GET request works but POST returns 404 浏览器获取请求 404'd 但适用于 Postman 应用程序 - Browser get request 404'd but works with Postman app 通过Axios发送发布请求会在Spring-Boot后端生成一个空的RequestBody。 在Postman中工作,但不能通过Axios发布请求工作 - Sending a post request through Axios is generating an empty RequestBody in Spring-Boot backend. Works in Postman but not through Axios post request Axios 获取请求返回错误未定义 - Axios get request returns error UNDEFINED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM