[英]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.