Android Question webview

elitevenkat

Active Member
Licensed User
Longtime User
how to provide login id and password to a webview ?
i had tried this way
B4X:
    WebView1.LoadUrl("https://xxx.com")

Private Sub WebView1_UserAndPasswordRequired (Host As String, Realm As String) As String()
    Log(Host & " host" & Realm & " - ")
    Return Array As String("88988", "password")
End Sub
does not work.
any help?
 

teddybear

Well-Known Member
Licensed User
how to provide login id and password to a webview ?
i had tried this way
B4X:
    WebView1.LoadUrl("https://xxx.com")

Private Sub WebView1_UserAndPasswordRequired (Host As String, Realm As String) As String()
    Log(Host & " host" & Realm & " - ")
    Return Array As String("88988", "password")
End Sub
does not work.
any help?
Does the site use basic authentication.?
See here
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
what "does not work?" the event? the values returned? both?

how - exactly - does the webpage require authorization?
(eg., it might be possible to send credentials to the server in the request headers.)
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
what "does not work?" the event? the values returned? both?

how - exactly - does the webpage require authorization?
(eg., it might be possible to send credentials to the server in the request headers.)
Both.
I don't know the authentication method. From the browser when I open the url, it is showing login page and after entering the credentials, it gets logged in . Is it possible get the login and password as input in webview ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if, when you access the url in a browser, you get a little login dialog, you should see the same little login dialog in webview. if you would post the url, we could see for ourselves. we don't need your credentials. just be aware that a webview is not a browser; some things a browser supports are not supported by webview.

the server has several ways to handle authentication/authorization: in an http response header, serving its own login page, accepting your credentials in an http request header, as posted data or as part of the url. in theory, you could try them all one by one, but it's helpful to know exactly what the server is expecting, if possible.

a lot depends on what the dialog you saw looks like. if the server does not send an http response indicating that authentication is required, the b4a event is not triggered.
(in theory, that event is supposed to trigger a little homemade login dialog. b4a shortens the process by simply returning the id and password as a string array. if you were writing an app for the world where every user had her own login, then you would need to write the dialog yourself. follow?)

if the server is handling the authentication with its own login page, then, basically, you have to fill it in (at least the first time you visit the url in the same session).
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
If it's not a basic authentication popup, then probably it's a normal login form.

You should fill in the form as stated previously and submit it by using javascript.

Example:

B4X:
wvEx.executeJavascript(yourWebView,"document.forms[0].userNameField.value='" & username & "';document.forms[0].passwordField.value='" & userPassword &"';document.forms[0].submit();")

where wvEx is an initialized webViewExtras object, userNameField is the field of the form containing the username and passwordField the one for the password. You should get these two from the page source of the form.
 
Upvote 0
Top