I have wrapped a Vue
app into a Cordova container and deployed on Android via Android Studio. Each request that goes out to my server is failing with the message Error: Network Error
.
This is not an issue in browser or iOs.
I have researched this issue and tried various solutions:
I have installed the cordova-plugin-whitelist
plugin and configured as described in the documentation
I have set permissions in the AndroidManifest.xml
file:
<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"
tag in meta:<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';">
I have changed my server address from localhost:3000
to my server's IP address as instructed in this answer: Network error with axios and android emulator - I also tried to run it via a local-tunnel to have a "real" API URL - same issue
As instructed in the thread above, I have also added headers:
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json"
Still Error: Network Error
. I am almost sure this has to do with permissions but there is nothing more I could configure to make it work.
I am testing this on Android 10.0+ device using Cordova 10 .
Axios on 0.20.0.
I found a solution for my problem. It looks like Android is not allowing requests to http by default, as stated in this thread: Internet permission not working in oreo and pie
Changing the localtunnel to https
solved the issue for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.