只有一些网址在Webview中无法加载。

huangapple go评论95阅读模式
英文:

Only some URLs not loading in Webview

问题

代码

  1. final WebView mWebView = (WebView) rootView.findViewById(R.id.webview);
  2. mWebView.setWebViewClient(new WebViewClient());
  3. mWebView.getSettings().setLoadsImagesAutomatically(true);
  4. mWebView.getSettings().setJavaScriptEnabled(true);
  5. mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  6. mWebView.loadUrl("https://www.onlineradiofm.in/");
  7. 我尝试在WebView中加载这个URLWebView是空的
  8. 这个URL有什么问题吗
  9. 我尝试用其他链接替换URL它可以正常工作
英文:

Code

  1. final WebView mWebView = (WebView) rootView.findViewById(R.id.webview);
  2. mWebView.setWebViewClient(new WebViewClient());
  3. mWebView.getSettings().setLoadsImagesAutomatically(true);
  4. mWebView.getSettings().setJavaScriptEnabled(true);
  5. mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  6. mWebView.loadUrl("https://www.onlineradiofm.in/");

Im trying to load this URL in webview and the webview is empty.
What's wrong with this URL?
I tried replacing the URL with other links and it works perfectly.

答案1

得分: 1

已成功完成HTTPS URL的SSL握手。

为了调试WebView,请添加以下代码并使用Chrome浏览器的chrome://inspect功能检查WebView。

  1. WebView.setWebContentsDebuggingEnabled(true);

步骤1:创建一个Web客户端:

  1. WebViewClient client = new WebViewClient(){
  2. @Override
  3. public void onReceivedSslError(WebView view, SslErrorHandler handler,
  4. SslError error) {
  5. //super.onReceivedSslError(view, handler, error);
  6. handler.proceed(); // 这将忽略SSL错误并继续执行
  7. }
  8. };

步骤2:将客户端添加到WebView中:

  1. mWebView.setWebViewClient(client);

祝编码愉快...

英文:

It's been a SSL handshake failed for HTTPS URL.

for debugging the webview, pls add following line and you can inspect webview Using chrome browser chrome://inspect.

  1. WebView.setWebContentsDebuggingEnabled(true);

Step-1: Create a webclient:

  1. WebViewClient client = new WebViewClient(){
  2. @Override
  3. public void onReceivedSslError(WebView view, SslErrorHandler handler,
  4. SslError error) {
  5. //super.onReceivedSslError(view, handler, error);
  6. handler.proceed(); // which ignores ssl errors and proceed further
  7. }
  8. };

Step-2: add client into webview

  1. mWebView.setWebViewClient(client);

Happy coding...

huangapple
  • 本文由 发表于 2020年8月8日 07:43:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63310426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定