且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法加载资源:net :: ERR_CLEARTEXT_NOT_PERMITTED

更新时间:2022-03-19 23:25:56

经过几天的努力,这对我有用,我希望这对您也有用. 将其添加到代码顶部的CONFIG.XML中.

After a few days of struggle, this works for me, and I hope this also works for you. add this to your CONFIG.XML, top of your code.

<access origin="*" />
<allow-navigation href="*" />

和这个,在android平台下.

and this, under the platform android.

<edit-config file="app/src/main/AndroidManifest.xml" 
   mode="merge" target="/manifest/application" 
   xmlns:android="http://schemas.android.com/apk/res/android">
     <application android:usesCleartextTraffic="true" />
     <application android:networkSecurityConfig="@xml/network_security_config" />
 </edit-config>
 <resource-file src="resources/android/xml/network_security_config.xml" 
 target="app/src/main/res/xml/network_security_config.xml" />

将以下代码添加到此文件"resources/android/xml/network_security_config.xml".

add the follow code to this file "resources/android/xml/network_security_config.xml".

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">YOUR DOMAIN HERE/IP</domain>
    </domain-config>
</network-security-config>