Working with HTTP

The System.Net namespace contains several classes to make working with the HTTP protocol easier. HTTP is the standard protocol for communicating on the World Wide Web, often just called the Web. The examples in this section use the HTTP classes to create a program that obtains a Web page. Listing 24.3 uses the HttpWebRequest, HttpWebResponse, and HttpStream classes to obtain a Web page.

Listing 24.3. Creating an HTTP Client: SiteReader.cs
 using System; using System.IO; using System.Net; using System.Text; /// <summary> /// Reads a Web page. /// </summary> class SiteReader { static void Main(string[] args) { try { ASCIIEncoding ASCII = new ASCIIEncoding(); byte[] buf = new byte[2048]; HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create( ...

Get C# Unleashed 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.