I am developing a React Native app using Expo and I recently ran into a weird issue. API requests don't work on Android devices however they're totally fine on iOS. The server I'm trying to connect to isn't localhost. I tried to use axios and fetch, both result in Network Error and the server doesn't receive a request. I also made requests to open APIs which got me the same error, so I believe the problem isn't on the server's side.
Here's the code of the request:
const axiosInstance = axios.create({
timeout: 120000,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
})
const res = await axiosInstance.post(`${serverHostApi}/merchant/login`, payload)
Here's the stack trace:
Network Error
- node_modules\axios\lib\helpers\normalizeHeaderName.js:8:14 in processHeader
* http://192.168.150.71:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:226876:26 in handleError
- node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:575:10 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:389:6 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425:19 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
I'm using Expo 38.0.0, React Native SDK 38.0.2. Any help would be highly appreciated!
Only way that I found to resolve is downgrade the version. Or you should make sure that TLS 1.0 and TLS 1.1 is disabled on the server.
"axios": "0.24.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With