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

Get C# Primer: A Practical Approach 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.