Chapter 34. Visual Basic and the Internet

In today's network-centric world, it is very likely that applications will need to work with other computers over a private network, the Internet, or both. This chapter details how to do the following:

  • Download resources from the Web

  • Design your own communication protocols

  • Reuse Internet Explorer in your applications

Downloading Internet Resources

Downloading content from the Web is very easy, and in this chapter you will throw together a basic application before getting into some meatier topics. This application downloads HTML from a Web page and displays it in a text box. Later, you will learn how you can display HTML properly by hosting Internet Explorer (IE) directly using the WebBrowser control in Windows Forms applications, but for now, you will just use plain text.

In order to download a Web page, you need to be able to identify the remote page that you wish to download, make a request of the web server that can provide that page, listen for the response, and download the data for the resource.

The relevant classes for this example are System.Uri, System.Net.WebRequest, System.Net.HttpWebRequest, and System.Net.HttpWebResponse:

  • System.Uri is a useful general-purpose class for expressing a Uniform Resource Identifier (URI). A Uniform Resource Locator (URL) is a type of URI (although, in reality, the terms are so confused that they are often used interchangeably). A URI, however, is "more than" a URL, which is why this .NET class is Uri and ...

Get Professional Visual Basic® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.