WEBVIEW with username and password

sea121

Member
Licensed User
Longtime User
Hello All,

Please I need Your help, i have to access automatically to a protected webserver with username and password for to collect the images from a webcam.

I done this easily by Visual Basic 6 on windows, but on android i can not to find the solution... can anyone help me ?

Many Thanks.

Fabrizio
 

sea121

Member
Licensed User
Longtime User
Hello Erel,

Many Thanks for you fast reply, in VB6 I use this code :

Inet1(Index).URL = strURL
Inet1(Index).Username = Username.text
Inet1(Index).Password = Password.text
Inet1(Index).AccessType = icDirect
Inet1(Index).Protocol = icHTTP
Inet1(Index).RequestTimeout = 500

If Inet1(Index).StillExecuting = False Then Inet1(Index).Execute "", "GET"

I am asking you if it is possible to reply this using webview... I will looking for http utils.. as you suggest me.

Best Regards.

Fabrizio
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Have you tried to open the secure webpage in a WebView yet?

Does the WebView show a Dialog box where you can enter username and password?
So you can successfully log in and now you want the WebView to save the username and passsword and automatically log you in on sebsequent visits to the page?

The B4A WebView has no support for (javascript) Dialog boxes - Alert, Confirm etc.
So a lot depends on how the web page asks for usename and password.

If the web page uses (or tries to use) a Dialog box then it probably won't work.
You can enable support for some types of Dialog with my WebViewExtras library and it's addWebChromeClient method.
Currently addWebChromeClient enables Alert, Confirm and Prompt Dialogs.
So if your web page uses a Dialog to get the username and password then one of those Dialogs may work BUT i suspect i'd have to update the library to add support for the specific type of Dialog that requests username and password.

However if the web page uses a web page form to enable the user to enter username and password then it's just a case of finding the native Android WebView methods that enable the entered username and password to be saved.

That's typically done (in a commercial browser) using cookies and i think cookies are enabled by default with the WebView but that may only be session cookies.
A session cookie lasts only while the WebView is created, once the Activity containing the WebView is destroyed the session cookies are also destroyed.
So the username and password would only be saved as long as your Activity exists.

If this is the case then you'd want to find a method to enable persistent cookies - cookies that persist after your Activity has been closed.

Post again with some more info so we know exactly how you web page requires the user to login.

Martin.
 
Upvote 0

sea121

Member
Licensed User
Longtime User
Hello Martin,

thank You very much for your help, the server is a Panasonic IP Camera :

BL-C210
Version 4.31R00
Running in IPv4 mode.

the URL string that I use for to see the camera images is :

http://192.168.9.253:80/SnapshotJPEG?Resolution=320x240&Quality=Motion

i don't know which method is used for autentication in this IPCAM

in the windows VB6 code the access with username and password is automatically managed by the INET.ocx

as i told before i need to do the same in B4A .. and i don't see how...

Thanks again.

Fabrizio
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I have done a little research and found out some useful info.

First there is official documentation for your camera's CGI web interface, the english version is available here: http://csj.psn-web.net/netwkcam_net/download/us/document/NEW_Camera_CGI_Interface_v4.30.pdf.
If you search the Panasonic site you might find it's available in other languages.

Your camera uses HTTP basic authentication.
So the question now is does the B4A WebView support HTTP basic authentication?

Since version 1.70 B4A WebView has a new event:
WebView_UserAndPasswordRequired event allows accessing protected sites.

The WebView documentation simply says:

UserAndPasswordRequired (Host As String, Realm As String) As String()

A search of the forum returns no examples of how to use this event - it must return an Array of Strings.
But looking at the WebView source code and the official documentation it looks as though that Array of String must be an Array of 2 Strings username and password - in that order.

So in your Activity you want to create a Sub:

B4X:
Sub WebView1_UserAndPasswordRequired (Host As String, Realm As String) As String()
   Return Array As String("your_username", "your_password")
End Sub

Assuming that the only web page your WebView will display that requires authentication is the camera web interface you can discard the Host and Realm Strings.

If there is a chance that the user will navigate to other web pages that require authentication then you'd need to examine the Host String to determine which username and password are required.

Martin.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
I have done a little research and found out some useful info.

First there is official documentation for your camera's CGI web interface, the english version is available here: http://csj.psn-web.net/netwkcam_net/download/us/document/NEW_Camera_CGI_Interface_v4.30.pdf.
If you search the Panasonic site you might find it's available in other languages.

Your camera uses HTTP basic authentication.
So the question now is does the B4A WebView support HTTP basic authentication?

Since version 1.70 B4A WebView has a new event:


The WebView documentation simply says:



A search of the forum returns no examples of how to use this event - it must return an Array of Strings.
But looking at the WebView source code and the official documentation it looks as though that Array of String must be an Array of 2 Strings username and password - in that order.

So in your Activity you want to create a Sub:

B4X:
Sub WebView1_UserAndPasswordRequired (Host As String, Realm As String) As String()
   Return Array As String("your_username", "your_password")
End Sub

Assuming that the only web page your WebView will display that requires authentication is the camera web interface you can discard the Host and Realm Strings.

If there is a chance that the user will navigate to other web pages that require authentication then you'd need to examine the Host String to determine which username and password are required.

Martin.
Bad to see, that B4J Webview don't have this Event or I miss something.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
It is better to post B4J related questions or comments in B4J forum.
Sorry Erel but it's a little confusing when you search the Forum you get both B4A and B4J feeds.
 
Upvote 0
Top