Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React Native https axios resquest在Android上出现网络错误,但在iOS上没有_Javascript_Android_React Native_Axios - Fatal编程技术网

Javascript React Native https axios resquest在Android上出现网络错误,但在iOS上没有

Javascript React Native https axios resquest在Android上出现网络错误,但在iOS上没有,javascript,android,react-native,axios,Javascript,Android,React Native,Axios,我正在构建我的react本机应用程序,并将后端URL用作,在开发过程中一切正常。但当我构建我的应用程序并将其安装在android设备上时,它无法工作,我记得有人告诉我,android默认只允许https请求。因此,我将URL更改为web应用程序正在使用的URL,即。。。(非自签名TSL证书)现在android可以发送请求,但它们都返回为网络错误s(当构建和在模拟器上运行时),但在iOS模拟器上运行良好。我是应用程序开发新手,在网上找不到任何解决方案。也许我错过了一个选择 我的axios设置,正在

我正在构建我的react本机应用程序,并将后端URL用作,在开发过程中一切正常。但当我构建我的应用程序并将其安装在android设备上时,它无法工作,我记得有人告诉我,android默认只允许https请求。因此,我将URL更改为web应用程序正在使用的URL,即。。。(非自签名TSL证书)现在android可以发送请求,但它们都返回为
网络错误
s(当构建和在模拟器上运行时),但在iOS模拟器上运行良好。我是应用程序开发新手,在网上找不到任何解决方案。也许我错过了一个选择

我的axios设置,正在发送请求:

const customAxios = axios.create({
        baseURL: baseURL,
        timeout: 6000,
    });

...

const response = await customAxios.post('/login', {
        email,
        password,
    });
错误堆栈:

Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:81)
    at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:388)
    at XMLHttpRequest.js:501
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:436)
    at MessageQueue.js:111
    at MessageQueue.__guard (MessageQueue.js:384)

https URL在ios和web应用程序上运行

在您的清单文件中添加
android:usesCleartextTraffic=“true”
内部应用程序标记

<application
  xmlns:tools="http://schemas.android.com/tools"
  tools:replace="android:allowBackup"
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:usesCleartextTraffic="true">...
</application>
。。。

您使用的是哪个axios版本?“axios”:“^0.19.0”axios 0.19.0中存在问题。如果您降级到0.18.0,则此问题将得到解决。但没有解决此问题。请确保您在清单中的
标记内有
android:usesCleartextTraffic=“true”
,并添加这些权限:
这也是我的问题!!必须添加安卓:usesCleartextTraffic=“true”。谢谢@VLazzarova考虑^