I have a react native app that is throwing a Network Error when trying to communicate with the backend api.
Troubleshooting I've tried:
- The same payload works in Postman (so the problem is the simulator/app, not the api)
- Using Axios (via
await axios(config)) - Tried using both the localhost (http) and production (https) servers as the backend, same error
- Enabled all the App Transport Security Settings configs (Allow Arbitrary Loads, added Exception Domains)
- The content type is specified in the headers
- The simulator is connected to internet (I tried the browser)
Config:
{"data": null, "headers": {"Content-Type": "application/json", "X-JWT": "..."}, "method": "GET", "url": "https://example.com/..."}
Error:
{"message":"Network Error",
"name":"Error",
"stack":"createError@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:156907:26\nhandleError@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:156693:69\ndispatchEvent@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:30339:31\nsetReadyState@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:29485:33\n__didCompleteResponse@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:29291:29\nemit@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:2264:42\n__callFunction@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:3086:36\n@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:2810:31\n__guard@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:3037:15\ncallFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.exampleapp:2809:21\ncallFunctionReturnFlushedQueue@[native code]",
"config":{
"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,
"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","X-JWT":"..."},
"url":"https://example.com/...",
"method":"get",
"data":"null"
},
"status":null}
Technical Environment:
- React Native: 0.64.1
- Simulator: iOS 15.2 iPhone 13
- Device: macOS Monterey (12.0.1), Apple M1