Android Question Read https web page to WebView

cenyu

Active Member
Licensed User
Longtime User
Can anyone give me a working example with this?
I can't do this alone....:(
 

cenyu

Active Member
Licensed User
Longtime User
Yes but blank page is shown.... My certificate is Self signed...may be this is the problem?
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim JoCert As JavaObject = Me
    JoCert.RunMethod("disableSSLTest", Null)
    WebView1.LoadUrl("https://www.b4x.com")
End Sub


#if JAVA
import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public static void disableSSLTest() {

     TrustManager[] trustAllCerts = new TrustManager[] {
         new X509TrustManager() {   
           public java.security.cert.X509Certificate[] getAcceptedIssuers() {
             return null;
           }
           public void checkClientTrusted(
               java.security.cert.X509Certificate[] certs, String authType) {
           }
           public void checkServerTrusted(
               java.security.cert.X509Certificate[] certs, String authType) {
           }
         }
     };

     // Install the all-trusting trust manager
     try {
       SSLContext sc = SSLContext.getInstance("TLS");
       sc.init(null, trustAllCerts, new java.security.SecureRandom());
       HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
     } catch (GeneralSecurityException e) {
     }
   }
#end if
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Yes but blank page is shown
Not true

WhatsApp Image 2020-08-11 at 14.40.44.jpeg
 

Attachments

  • WebViewB4X.zip
    142.6 KB · Views: 188
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
He probably think on his own domain with self signed cert.
That´s maybe an Issue TOO, right.

Basically a webview can show SSL Sites without a problem.

The question was if it is possible or not.

He later edited his post.

Originally he posted just the text
Yes but blank page is shown....
 
Upvote 0

cenyu

Active Member
Licensed User
Longtime User
Into browser all work correctly

Finaly i success to read my https link with this code and WebViewExtras2:
B4X:
    Dim client As DefaultWebViewClient
    client.Initialize("client")
    WebSettings.setDefaultTextEncodingName(WebView1,"utf-8")
    WebViewExtras1.Initialize(WebView1)
    WebViewExtras1.JavaScriptEnabled=True
    WebViewExtras1.SetWebViewClient(client)
    WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
    WebView1.LoadUrl(appURL)

Thank you!
Respect!
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Dear DonManfred...I try your coda also i try code from Pendrush but not work for me....Blank page only

I have C# MVC web site
On my IIS i create self singnet cert...
The url is https://locaclhost/MobileOffice/Phone/Auth/Authorize/869817035803227

This can't be loaded even into your sample
Excuse me - how do you expect a page located on your localhost to be visible in your app? Your phone doesn't know what localhost is so you need to use either internal IP if your app works in your local network or external IP or a domain.
 
Upvote 0
Top