Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

WebRequest

Synopsis

Because many Internet protocols are request-response synchronous protocols, this class serves as a base type for any and all request-response style of network communication. As such, a .NET programmer will never create a WebRequest type directly—instead, a static method on this class, Create( ), is used as a “virtual constructor” to create a subtype of WebRequest that matches the protocol scheme requested. For example, if the string http://www.oreilly.com is passed to Create( ), an instance of HttpWebRequest is handed back. Out of the box, only “http”, “https”, and “file” are supported.

Once obtained, a .NET programmer can manipulate the common properties of the WebRequest type to control various aspects of the request. Alternatively, downcast the generic WebRequest reference to the concrete type returned to access protocol-specific aspects of that protocol—for example, the returned object from WebRequest.Create("http://www.oreilly.com") will be a HttpWebRequest, so it is safe to cast it as such. This allows access to the Accept and SendChunked properties/headers in the request. Be sure to manipulate these properties before the request is sent, or the modifications will have no effect.

Use the GetResponse( ) method to obtain a WebResponse object corresponding to the response that the remote server sent. This means that the request is sent, and the response harvested. The methods BeginGetResponse( ) and EndGetResponse( ) are asynchronous versions of GetResponse( ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata