O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.8. The Web Request/Response Model

In this section we'll walk through the steps necessary to access a page over the Internet. We use the WebRequest, WebResponse, and Uri classes. They are defined within the System.Net namespace. Let's create a class called PageReader. First, we need a Uniform Resource Locator (URL) address. The user may optionally pass in a string representation to the PageReader constructor; otherwise, by default, we use the address of my company's home page:

 public class PageReader { private Uri uri; private bool validateUrl( string url ) { ... } public PageReader( string url ) { if ( url != null && url != String.Empty && validate_url( url )) uri = new Uri( url ); } public PageReader() : this( "http://www.objectwrite.com" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required