HOWTO: Use WebBrowser HEADERS Param in Navigate Method

Last reviewed: August 22, 1997
Article ID: Q172998
The information in this article applies to:
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Enterprise Edition, 32-bit only, for Windows, version 4.0

SUMMARY

Microsoft Internet Explorer 3.0 includes a custom ActiveX control called "WebBrowser." When you use WebBrowser in combination with Microsoft Visual Basic, you can design powerful custom solutions that include Internet Web browsing features. This article illustrates how to use the WebBrowser control HEADERS parameter in the Navigate method within Microsoft Visual Basic.

MORE INFORMATION

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

  1. Create a new Standard .exe project in Microsoft Visual Basic 5.0. Form1 is created by default.

  2. From the Project menu, click Components.

  3. Select the Microsoft Internet Controls component. Click OK.

  4. Add the following controls to Form1:

       Control           Name
       --------------    ---------
       Command Button    Command1
       WebBrowser        WebBrowser1
    
    

  5. 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
    
    

  6. From the File menu, click Save Project1.

  7. 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.

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q155969
   TITLE     : HOWTO: Distribute the WebBrowser Control

   ARTICLE-ID: Q162719
   TITLE     : HOWTO: Use the WebBrowser Control from Visual Basic 5.0
Keywords          : vb432 VB4WIN vb5all
Technology        : kbInetDev
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.