忽略webview中的ssl证书请求

时间:2015-12-13 22:39:58

标签: android asp.net webview

我制作了一个涉及aspx pages的小应用程序,我试着打开它我的网页视图我有空白屏幕。

我尝试用Chrome浏览器打开它,它给我需要证书

enter image description here

我的代码非常简单我添加了一些文档来解释发生了什么

@SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        Bundle bundle = getIntent().getExtras();
        if(bundle != null){
            urlSite = bundle.getString("passed_url");
        }
     _toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(_toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    _toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    webView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webView.getSettings();

    // enable javascript
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setPluginState(WebSettings.PluginState.ON_DEMAND);


    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            new ParseURl().execute(new String[]{urlSite});
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    if(urlSite != null){
        webView.clearCache(true);
        webView.loadUrl(urlSite);
       // webView.loadUrl("file:///android_asset/af.html");
    }
}

1 个答案:

答案 0 :(得分:3)

经过一些研究后,我找到了答案,只是覆盖了onReceivedSslError方法并将其传递给

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    handler.proceed(); // Ignore SSL certificate errors
}