The following example creates a mini-browser and uses the HEADERS parameter
of the Navigate method. The HEADERS parameter has different options; this
example uses the Authorization option. Adding this header allows you to
gain access to a password protected URL without being asked for user name
and password via a dialog box generated by the browser control. Note that
code below applies only when Basic scheme is used. Please see HTTP Protocol
specification (available at
http://www.w3.org) to get more details on HTTP
Authentication process.
The format for Authorization header is as follow:
Authorization: Basic XXXXXXX
Where XXXXXX is Base64 encoded string: "UserName:UserPassword." Base64 is
described in RFC1113 and some public domain utilities for Base64
decoding/encoding are available.
Step-by-Step Example
- Create a new Standard .exe project in Microsoft Visual Basic 5.0. Form1 is created by default.
- From the Project menu, click Components.
- Select the Microsoft Internet Controls component. Click OK.
- Add the following controls to Form1:
Control Name
-------------- ---------
Command Button Command1
WebBrowser WebBrowser1
- In Form1's code window, add the following code:
Option Explicit
Private Sub Command1_Click()
WebBrowser1.Navigate URL:= "http://www.microsoft.com" _
,Headers:= "Authorization: Basic XXXXXX" & chr$(13) & chr$(10)
' Note: All headers must be terminated with a
' carriage return linefeed pair.
If WebBrowser1.Visible = False Then
WebBrowser1.Visible = True
End If
End Sub
- From the File menu, click Save Project1.
- From the Run menu, click Start. Note that when you click Command1, the WebBrowser appears and automatically loads the URL specified in the URL parameter of Navigate.