Rya*_*zzo 2 https ios ios-simulator react-native axios
Network Error我有一个 React Native 应用程序,在尝试与后端 api 通信时抛出一个异常。
我尝试过的故障排除:
await axios(config))配置:
{"data": null, "headers": {"Content-Type": "application/json", "X-JWT": "..."}, "method": "GET", "url": "https://example.com/..."}
Run Code Online (Sandbox Code Playgroud)
错误:
{"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}
Run Code Online (Sandbox Code Playgroud)
技术环境:
我使用 RN 也遇到同样的问题0.64.2
该问题似乎与 Chrome 调试器有关。
要修复网络错误,我只需禁用调试器或使用react-native-debugger:
https://github.com/jhen0409/react-native-debugger
如果仍然不起作用,请尝试设置data: undefined请求GET
data: undefined修复和其他可能修复
的来源: https://github.com/axios/axios/issues/3192
更新:对于较新的 RN 版本,我使用 Flipper:RN 0.66、Flipper App 0.99 和 Flipper 依赖项 0.99。Flipper App 0.149+ 也可以工作,但在 Android 上网络扩展有时似乎工作得不太好。
我注意到,在我的具体 RN 版本中,使用 React Native 升级助手中推荐的 Flipper 版本对于 Android 和 iOS 来说效果最好。
| 归档时间: |
|
| 查看次数: |
3451 次 |
| 最近记录: |