Ionic 通过电容器构建的离子应用程序无法处理其余API请求

tgabmvqs  于 2022-12-09  发布在  Ionic
关注(0)|答案(1)|浏览(157)

从构建的Ionic(电容器)应用程序调用REST API时出现问题。在Web(开发)中一切正常,但当我构建应用程序时,我得到net::ERR_CONNECTION_TIMED_OUT(当我尝试调用GET请求时)Error Picture

我的Android清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="io.ionic.starter">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:networkSecurityConfig="@xml/network_security_config"
        android:usesCleartextTraffic="true">

        <activity
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:name="io.ionic.starter.MainActivity"
            android:label="@string/title_activity_main"
            android:theme="@style/AppTheme.NoActionBarLaunch"
            android:launchMode="singleTask">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

电容器配置ts

从'@capacitor/cli'导入{电容器配置};

const config: CapacitorConfig = {
  appId: 'unitsys.liteController.app',
  appName: 'LiteControllerApp',
  webDir: 'build',
  bundledWebRuntime: false,
  cordova: {},
  server: {
    cleartext: true,
    allowNavigation:[
      "localhost:8100/*"
    ]
  }
}

export default config;

配置.xml(安卓/应用程序/源代码/主/资源/xml/)

<?xml version='1.0' encoding='utf-8'?>
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <access origin="*" />
  
  
</widget>

网络安全配置.xml(安卓/应用程序/源代码/主/res/xml/)

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">10.0.2.2</domain>
        <domain includeSubdomains="true">192.168.1.194</domain>
    </domain-config>
kmb7vmvb

kmb7vmvb1#

就像下面的例子一样,capacitor.config.ts

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'io.ionic.starter',
  appName: 'ivlab5-mobile-app',
  webDir: 'dist',
  bundledWebRuntime: false,

  server: {
    androidScheme: "http",
    cleartext: true,
    allowNavigation: [
      "http://test.test.id/api/*"
    ]
  }
};

export default config;

相关问题