Android Tutorials Use WebView to access HTTPS URLs to handle sslerror samples _android

Source: Internet
Author: User
Tags blank page

In Android, WebView is a control used to load HTTP and HTTPS Web pages to local applications. By default, the Loadurl (String URL) method allows you to successfully load pages such as http://www.baidu.com. However, when the HTTPS page with the SSL layer is load, such as https://money.183.com.cn/, if the site's security certificate is not authenticated on Android, WebView becomes a blank page, It doesn't jump out of a risk box like a PC browser. Therefore, we must deal with this situation.

Android has two classes to deal with

Copy Code code as follows:

Import Android.net.http.SslError;
Import Android.webkit.SslErrorHandler;

The specific usage is as follows:

Copy Code code as follows:

WebView WV = (webview) Findviewbyid (R.id.webview);
Wv.setwebviewclient (New Webviewclient () {
public void Onreceivedsslerror (WebView view, Sslerrorhandler handler, sslerror error) {
Handler.cancel (); Default processing, webview into blank pages
Handler.process (); Accept Certificate
Handlemessage (msg); Other processing
}

If you simply accept all the certificates, then you can directly adjust the process () method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.