Permalink
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (41 sloc) 3.24 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
HTTP
03/30/2017
.net-framework
article
VB
CSharp
C++
jsharp
protocols, HTTP
sending data, HTTP
HttpWebResponse class, sending and receiving data
HTTP
receiving data, HTTP
application protocols, HTTP
Internet, HTTP
network resources, HTTP
HTTP, about HTTP
HttpWebRequest class, sending and receiving data
985fe5d8-eb71-4024-b361-41fbdc1618d8
10
mcleblanc
markl
markl

HTTP

The .NET Framework provides comprehensive support for the HTTP protocol, which makes up the majority of all Internet traffic, with the xref:System.Net.HttpWebRequest and xref:System.Net.HttpWebResponse classes. These classes, derived from xref:System.Net.WebRequest and xref:System.Net.WebResponse, are returned by default whenever the static method xref:System.Net.WebRequest.Create%2A?displayProperty=nameWithType encounters a URI beginning with "http" or "https". In most cases, the WebRequest and WebResponse classes provide all that is necessary to make the request, but if you need access to the HTTP-specific features exposed as properties, you can typecast these classes to HttpWebRequest or HttpWebResponse.

HttpWebRequest and HttpWebResponse encapsulate a standard HTTP request-and-response transaction and provide access to common HTTP headers. These classes also support most HTTP 1.1 features, including pipelining, sending and receiving data in chunks, authentication, preauthentication, encryption, proxy support, server certificate validation, and connection management. Custom headers and headers not provided through properties can be stored in and accessed through the Headers property.

HttpWebRequest is the default class used by WebRequest and does not need to be registered before you can pass a URI to the WebRequest.Create method.

You can make your application follow HTTP redirects automatically by setting the xref:System.Net.HttpWebRequest.AllowAutoRedirect%2A property to true (the default). The application will redirect requests, and the xref:System.Net.HttpWebResponse.ResponseUri%2A property of HttpWebResponse will contain the actual Web resource that responded to the request. If you set AllowAutoRedirect to false, your application must be able to handle redirects as HTTP protocol errors.

Applications receive HTTP protocol errors by catching a xref:System.Net.WebException with the xref:System.Net.WebException.Status%2A set to xref:System.Net.WebExceptionStatus. The xref:System.Net.WebException.Response%2A property contains the WebResponse sent by the server and indicates the actual HTTP error encountered.

See Also

Accessing the Internet Through a Proxy
Using Application Protocols
How to: Access HTTP-Specific Properties