webview中的网页为空白

时间:2012-02-13 12:24:01

标签: java android android-widget

我正在使用以下代码连接到https网站。但结果始终是一个空白页面。我已经搜索了很多。任何帮助将不胜感激。

    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {       try
        {
            InputStream keyStoreStream = getResources().openRawResource(R.raw.jssecacerts);
            KeyStore keyStore = null;
            keyStore = KeyStore.getInstance("BKS");
            keyStore.load(keyStoreStream, "mypwd".toCharArray());

                KeyManagerFactory keyManagerFactory = null;
            keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(keyStore, "mypwd".toCharArray());

           SSLContext context = SSLContext.getInstance("TLS");
           context.init(keyManagerFactory.getKeyManagers(), null, null);

           alertbox("before response", url);
           URL url1 = new URL(url);
           HttpsURLConnection urlConnection = (HttpsURLConnection) url1.openConnection();
           urlConnection.setSSLSocketFactory(context.getSocketFactory());
           InputStream in = urlConnection.getInputStream();
           alertbox("response", convertToString(in));
           view.loadData(convertToString(in), "text/html", "utf-8");               
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return true;
    }

1 个答案:

答案 0 :(得分:1)

你试过像

那样简单的事吗?
webview.loadUrl("URL HERE");