我正在尝试打开有证书问题的网站,经过长时间的研究后我发现通过覆盖onReceivedSslError
方法传递证书错误然后继续错误handler.proceed();
,但是当我打开网站时我得到了这个例外
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String[] urls = new String[]{url};
new ParseURl().execute(urls);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.equals("about:blank")) {
view.loadUrl(url);
}
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
异常日志
12-26 05:28:11.719 5681-5832/com.example.mina.speechrecognition D/dalvikvm: GC_FOR_ALLOC freed 350K, 13% free 4084K/4652K, paused 7ms, total 8ms
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/TilesManager: Starting TG #0, 0xb85683a0
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/TilesManager: new EGLContext from framework: b83b4440
12-26 05:28:12.599 5681-5681/com.example.mina.speechrecognition D/GLWebViewState: Reinit shader
12-26 05:28:13.067 5681-5681/com.example.mina.speechrecognition D/GLWebViewState: Reinit transferQueue
12-26 05:28:13.095 5681-5681/com.example.mina.speechrecognition W/Web Console: The page at https://noor.moe.gov.sa/Noor/login.aspx ran insecure content from http://www.moe.gov.sa/_layouts/15/MOE/script/MOECommon.js.
at null:1
12-26 05:28:18.935 5681-6039/com.example.mina.speechrecognition W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:401)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
12-26 05:28:18.951 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err: at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
12-26 05:28:19.011 5681-6039/com.example.mina.speechrecognition W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
12-26 05:28:19.115 5681-6039/com.example.mina.speechrecognition W/System.err: at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
12-26 05:28:19.119 5681-6039/com.example.mina.speechrecognition W/System.err: at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at com.example.mina.speechrecognition.WebActivity$ParseURl.doInBackground(WebActivity.java:156)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at com.example.mina.speechrecognition.WebActivity$ParseURl.doInBackground(WebActivity.java:150)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: at java.lang.Thread.run(Thread.java:841)
12-26 05:28:19.123 5681-6039/com.example.mina.speechrecognition W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:19.459 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:282)
12-26 05:28:19.459 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:595)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
12-26 05:28:19.463 5681-6039/com.example.mina.speechrecognition W/System.err: at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:398)
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err: ... 19 more
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
12-26 05:28:19.467 5681-6039/com.example.mina.speechrecognition W/System.err: ... 24 more
我anaylsis网站和提取ids
public class ParseURl extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
try {
listID.clear();
Document doc = Jsoup.connect(params[0]).get();
Elements inputs = doc.select("input[type=text], input[type=password], input[type=email]");
for (Element ele : inputs) {
listID.add(ele.attr("id"));
}
} catch (IOException e) {
e.printStackTrace(); // exception fired here
Log.i("error stack", e.getMessage());
}
if (listID.size() > 0) {
return true;
}
return false;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
// Toast.makeText(WebActivity.this, "Analysis site Done", Toast.LENGTH_LONG).show();
//startReadInput();
} else {
Toast.makeText(WebActivity.this, "your site dont have input to fill", Toast.LENGTH_LONG).show();
}
}
}
答案 0 :(得分:2)
我已尝试使用您的logcat中显示的网站网址,并且可以正常使用
final String url = "https://noor.moe.gov.sa/Noor/login.aspx";
WebView mWebView = (WebView) v.findViewById(R.id.webView);
mWebView.setInitialScale(1);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.equals("about:blank")) {
view.loadUrl(url);
}
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
mWebView.loadUrl(url);
这是截图