【问题标题】:Is it possible to allow mixed content in Flutter WebView是否可以在 Flutter WebView 中允许混合内容
【发布时间】:2021-06-22 02:26:01
【问题描述】:

我有一个问题,网页使用 SSL 保护,但页面内的视频和音频内容不是,源 URL 是 HTTP,这会阻止用户在 WebView 中播放这些类型的内容。消息如下:

"Mixed Content: The page at 'https://<page url>' was loaded over HTTPS, but requested an insecure video 'http://<video url>.mp4'. This request has been blocked; the content must be served over HTTPS.", source: https://<page url> (0)

是否有可能以某种方式允许或强制 WebView 加载混合内容并允许用户播放不受 SSL 保护的内容?

谢谢

【问题讨论】:

    标签: flutter http https webview


    【解决方案1】:

    webview_flutter 插件没有更改 Android WebView 混合内容模式的选项。

    相反,您可以使用我的 flutter_inappwebview 插件,它支持特定的 Android 网络视图选项。

    在您的情况下,您可以将 Android webview 选项 mixedContentMode 设置为值 AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW

    在这种模式下,WebView 将允许安全源从任何其他源加载内容,即使该源不安全。

    代码示例:

    child: InAppWebView(
      initialUrlRequest: URLRequest(url: Uri.parse("https://yourwebsite.com")),
      initialOptions: InAppWebViewGroupOptions(
        android: AndroidInAppWebViewOptions(
          mixedContentMode: AndroidMixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW
        )
      ),
    )
    

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 2021-08-01
      • 2013-08-21
      • 2016-12-28
      • 2015-02-26
      • 1970-01-01
      • 2019-03-20
      • 2018-08-28
      相关资源
      最近更新 更多