【问题标题】:W/SystemWebViewClient: URL blocked by whitelistW/SystemWebViewClient:被白名单阻止的 URL
【发布时间】:2021-11-02 13:17:20
【问题描述】:

我有一个 Angular 应用程序,我尝试将它包装在适用于 android 的 cordova 应用程序中。但是,当 android 上的 cordova 应用程序时,我无法将针对服务器的请求列入白名单。 在将 cordova 应用程序作为浏览器应用程序进行测试时,没有任何问题。 我已经阅读了很多关于 cordova 上的白名单行为的文章和帖子,但没有任何结果。

我使用的是cordova 10。在阅读时,我不应该使用cordova-plugin-whitelist,因为在这个版本中,这个插件已经集成在主框架中。 config.xml 中的配置在创建项目时已经自动生成。 这是我的 config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="de.acme.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" 
    xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>appname</name>
    <description>description</description>
    <author email="user@mail.de" href="https://mail.de">author</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <access origin="*" />
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

如您所见,带有访问源的标签是可用的。 我没有安装插件。但我也尝试安装cordova-plugin-whitelist。但这也没什么区别。

Angular 中的请求是带有 HTTPClient 的标准 GET 请求。但其他请求也不起作用。例如嵌入谷歌字体。

我想通过 GET 请求访问的服务器是我 LAN 中的服务器,地址如下:192.168.178.5:4003(特定端口!)

在 Logcat 中我收到此错误消息:

I/chromium: [INFO:CONSOLE(1)] "request: http://192.168.178.5:4003/api/audiobooks/tags", source: file:///android_asset/www/main.a7f87f00e27ff7637d70.js (1)
W/SystemWebViewClient: URL blocked by whitelist: http://192.168.178.5:4003/api/audiobooks/tags

我认为,这只是一个小配置问题。但我不知道应该在哪里寻找正确的解决方案。

谢谢

【问题讨论】:

    标签: android angular cordova


    【解决方案1】:

    如果您使用 HTTP,您可能需要允许 Android 使用明文流量。见:https://cordova.apache.org/docs/en/dev/guide/platforms/android/index.html#android-quirks

    如果您使用的是 cordova-android 10,请确保使用最新版本 (10.1.0),因为它包含重要的错误修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-06
      • 2015-03-03
      • 2021-06-28
      • 1970-01-01
      • 2017-03-24
      • 2019-05-13
      • 2014-02-28
      • 1970-01-01
      相关资源
      最近更新 更多