![](/img/trans.png)
[英]React Native throw Network Error when using Axios or Fetch in android
[英]axios requests throw “Network Error” on Android (Cordova container)
我已經將一個Vue
應用程序封裝到一個 Cordova 容器中,並通過 Android Studio 部署在 Android 上。 發送到我的服務器的每個請求都失敗,並顯示消息Error: Network Error
。
這在瀏覽器或 iO 中不是問題。
我研究了這個問題並嘗試了各種解決方案:
我已經安裝了cordova-plugin-whitelist
插件並按照文檔中的描述進行了配置
我在AndroidManifest.xml
文件中設置了權限:
<edit-file mode="merge" parent="/manifest/uses-permission" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</edit-file>
"Content-Security-Policy"
標簽:<meta data-n-head="1" http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';">
我已按照此答案中的說明將我的服務器地址從localhost:3000
更改為我服務器的 IP 地址: axios 和 android 模擬器的網絡錯誤- 我還嘗試通過本地隧道運行它以獲得“真實”的 API URL - 相同問題
按照上面線程中的指示,我還添加了標題:
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json"
仍然Error: Network Error
。 我幾乎可以肯定這與權限有關,但我無法再配置以使其正常工作。
我正在使用Cordova 10在Android 10.0+設備上對此進行測試。
在0.20.0 Axios公司。
我找到了解決我的問題的方法。 看起來 Android 默認不允許對 http 的請求,如該線程中所述: Internet 權限在 oreo 和 pie 中不起作用
將 localtunnel 更改為https
為我解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.