【发布时间】:2024-04-17 01:30:02
【问题描述】:
我正在使用依赖于许多 http 请求的 expo 构建 RN 应用程序。我同意我的后端,我们将使用 HTTPS 证书,但不知何故,我的 Android 模拟器对这些请求抛出了错误。一旦我们只尝试了 HTTP 请求,它就起作用了。当我尝试获取一些数据时出现此错误:
Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:473:29 in xhr.onerror
- node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 in setReadyState
- node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
- node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue
我已经尝试用
修改 AndroidManifest.xml 文件android:usesCleartextTraffic="true" tools:targetApi="28"
但仍然没有结果。我们有自己的 IP 服务器,当我尝试通过浏览器访问时,它会在我的应用程序中给出我想要的响应。所以看起来服务器在它周围的所有东西上都可以正常工作,只有我的应用程序不想获取这些数据。请问有人用HTTPS请求解决了这个问题吗?
【问题讨论】:
-
你尝试过使用像apisauce这样的http请求库吗?
-
还没有,但是您认为这有助于解决这个问题吗?
标签: react-native networking https fetch