gpt4 book ai didi

ssl - 尝试在 webview 中加载 URL 时出错 - android

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:46 27 4
gpt4 key购买 nike

由于 SSL 错误,我正在尝试在我的一项事件中加载 Web View 时,该 URL 显示为空白。

我已经尝试使用网络安全配置 XML 文件夹,但我不确定我是否理解我在做什么。任何帮助将不胜感激。

调试时,当我在 web View 中将 Google.com 作为 URL 加载时,页面加载正常。然后,当我尝试搜索特定站点时,它就在那里,但是当我单击它时,我在 Android Studio 的运行日志中收到 SSL 错误。

public class About_ALC extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about__alc);
final WebView webview = (WebView) findViewById(R.id.web_about_alc);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("https://andela.com/alc/");
}

the error message I receive in Android studio's is:

"E/chromium: [ERROR:ssl_client_socket_impl.cc(947)] handshake failed; returned -1, SSL error code 1, net_error -202"

最佳答案

您需要扩展 WebViewClient 以允许加载,尽管存在 ssl 错误,如下所示。

    // A new webclient that ignore ssl errors
private class IgnoreSSLErrorWebViewClient extends WebViewClient {
// You can all the class anything

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); // When an error occurs, ignore and go on
}
}

该站点存在 ssl 证书验证问题。当出现 ssl 验证错误时,默认的 WebViewClient 停止加载。此扩展将指示它忽略错误并继续。

所以更改行 webview.setWebViewClient(new WebViewClient());

webview.setWebViewClient(new IgnoreSSLErrortWebViewClient());

现在这对你来说应该可以正常工作了。

关于ssl - 尝试在 webview 中加载 URL 时出错 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57027277/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com