Downloading Text HTTP Data

Let's use the HTTP protocol in a program. We'll download the Microsoft Visual Basic Web page itself using the HTTP protocol. This page is named default.htm, and it resides at http://www.microsoft.com/vbasic. Let's name this new program HTTPer. Create that project in Visual Basic, making it an SDI program with the Application Wizard. Then add a rich text box (RichTextbox1) and an Internet Transfer control (Inet1) as we did in the previous example, FTPer:

Now we add a new item to the File menu—Get File—using the Visual Basic Menu Editor. When the user clicks this item, we'll download the HTML of the Visual Basic Web page. As with FTPer, place this item after the Close item in the File menu and give it the name GetFile. Now open that item's click event handler:

Private Sub GetFile_Click()
End Sub

To get the Visual Basic Web page, we use OpenURL() as we have before in this chapter. Because the URL we are opening is prefaced http:, OpenURL() will use the HTTP protocol. We open the Web page and place its text into our rich text box this way:

Private Sub GetFile_Click()
—> RichTextBox1.Text =
        Inet1.OpenURL("http://www.microsoft.com/vbasic/default.htm")
        .
        .
        .
End Sub

That's all there is to it. Now we can download HTML files using the HTTP protocol. When we run our program, the result appears in Figure 3.3.

 

Downloading the microsoft.com Visual Basic Web page.

We can also download binary data using OpenURL(), and we'll take a look at that now.

© 1997 by Steven Holzner. All rights reserved.