React native 使用axios进行本机响应-使用自签名https端点调用localhost时发生网络错误

React native 使用axios进行本机响应-使用自签名https端点调用localhost时发生网络错误,react-native,axios,React Native,Axios,我在VisualStudio中创建了带有传送带扩展的服务,以便在本地网络中访问它。我在我的安卓设备上安装了证书,所以在浏览器中调用它时会有绿色挂锁,服务运行良好。 然而,当使用axios从React本机应用程序调用它时,我收到了网络错误。 这是我的密码: const fetchData = async () => { console.log('url', `${Settings.API_URL}/location/GetDataByMyIp`); try {

我在VisualStudio中创建了带有传送带扩展的服务,以便在本地网络中访问它。我在我的安卓设备上安装了证书,所以在浏览器中调用它时会有绿色挂锁,服务运行良好。 然而,当使用axios从React本机应用程序调用它时,我收到了网络错误。 这是我的密码:

    const fetchData = async () => {
      console.log('url', `${Settings.API_URL}/location/GetDataByMyIp`);
      try {
        const result = await axios(
          `${Settings.API_URL}/location/GetDataByMyIp`,
        );
        console.log('result', result);
        ipData = {
          city: result.data.city,
          longitude: result.data.longitude,
          latitude: result.data.latitude,
        };
      } catch (e) {
        console.log('error', e);
      }
    };
    await fetchData();
在控制台中,我看到:

url https://192.168.1.14:45455/api/location/GetDataByMyIp
error Error: Network Error
    at createError (path_to_app\node_modules\axios\lib\core\createError.js:16)
    at EventTarget.handleError (path_to_app\node_modules\axios\lib\adapters\xhr.js:83)
    at EventTarget.dispatchEvent (path_to_app\node_modules\event-target-shim\dist\event-target-shim.js:818)
    at EventTarget.setReadyState (path_to_app\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:575)
    at EventTarget.__didCompleteResponse (path_to_app\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:389)
    at path_to_app\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:502
    at RCTDeviceEventEmitter.emit (path_to_app\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189)
    at MessageQueue.__callFunction (path_to_app\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425)
    at path_to_app\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112
    at MessageQueue.__guard (path_to_app\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373)
我试图将这一行添加到AndroidManifest.xml应用程序标记中,但仍然有错误

android:usesCleartextTraffic="true"
一些解决方案建议将其作为第二个参数添加到axios,但它不适用于React Native

new https.Agent({
    rejectUnauthorized: false,
});
我试着从互联网上呼叫其他服务,然后错误消失了

有什么解决办法吗?我没有找到更多的东西。我的最后一个想法是在Azure上托管服务,这样我就可以正确地签署SSL,但我想这必须是在本地运行它的一种方式

编辑:它通过http工作