本文介绍了webview.loadUrl()中的Android错误-找不到证书路径的信任锚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用于加载URL的 webview
,但不起作用.
I have a webview
for load url, but not work.
看看我的代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.webView);
//Log.d("rudyy", "aqui");
wv.loadUrl("https://tripulanteaims.tam.com.br/wtouch/wtouch.exe/index");
//Log.d("rudyy", "fim");
}
}
执行此代码时,android返回此错误:
When execute this code, android return this error :
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
请帮助我.
推荐答案
创建WebViewClient:
Create a WebViewClient:
private class WvClient extends WebViewClient
{
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError er) {
handler.proceed();
// Ignore SSL certificate errors
}
}
并将已初始化的WebViewClient("WvClient")设置为您的WebView(在这种情况下为"wv"):
And set the initialized WebViewClient ("WvClient") to your WebView ("wv" in that case):
wv.setWebViewClient(new WvClient());
或一行:
wv.setWebViewClient(new WebViewClient() {@Override public void onReceivedSslError(WebView v, SslErrorHandler handler, SslError er){ handler.proceed(); }});
这篇关于webview.loadUrl()中的Android错误-找不到证书路径的信任锚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!