'Axios request in Expo React Native app returns unexpected 405 error
I'm developing a React Native app with Expo and I'm using Axios to try sending http requests. Unfortunately, for every request I get a 405 status response.
This is the axios instance I've created to manage the requests (API url replaced with dummy for security reasons):
import axios from 'axios';
const instance = axios.create({
baseURL: 'https://actualapi.com',
headers: {
['Content-Type']: 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': '*'
}
});
export default instance;
The actual request (in a redux thunk function aka async action creator):
axios
.post(
requestPath,
// { withCredentials: true },
{ email: email }
)
.then((res) => {
console.debug(JSON.stringify(res));
checkEmailSuccess(res);
})
.catch((error) => {
console.debug(error);
checkEmailFail(error);
});
The error for every single request:
Request failed with status code 405
at node_modules\axios\lib\core\createError.js:16:14 in createError
at node_modules\axios\lib\core\settle.js:17:22 in settle
at node_modules\axios\lib\adapters\xhr.js:66:12 in onloadend
at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEventat node_modules\react-native\Libraries\Network\XMLHttpRequest.js:614:6 in setReadyState
at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:396:6 in __didCompleteResponse
at node_modules\react-native\Libraries\vendor\emitter\_EventEmitter.js:135:10 in EventEmitter#emit
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:414:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:113:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:4 in callFunctionReturnFlushedQueue
Solution 1:[1]
It was a wrong call. I was doing a POST instead of GET.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | gusti |
