The project is packaged as an apk and published on Android. When running, some Android phone requests failed to send, and the status code returned to 0 [Solution]

Project scenario:

Package the vue project originally developed on the mobile phone as an apk and release it on Android.


Problem Description:

Everything works fine when debugging in the browser. However, when it is packaged as an apk and installed on a mobile phone, some Android phone requests cannot be sent normally, the server does not receive the request, and the request status code returns 0.


Cause Analysis:

1. There are two reasons currently known to me for the request status code to be 0:
a. I canceled the request in the code
b .Request blocked
2. After checking the Android update documentation, I found that for security reasons after Android 9.0, only https is used for sending by default, unless set by the developer.

Insert image description here


solution:

If it is packaged through Cordova

You can find AndroidManifest.xml at this location in the project path
…/platforms/android/app/src/main/AndroidManifest.xml
File
Insert image description here

Add in this file
android:usesCleartextTraffic="true
Insert image description here
Package and publish again and install it on the mobile phone to send the request normally.

Guess you like

Origin blog.csdn.net/chen_CJH/article/details/115752017