The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.
Do not use the HttpWebRequest constructor. Use the WebRequest..::.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http:// or https://, WebRequest..::.Create returns an HttpWebRequest object.
You can make an asynchronous request to the resource using the BeginGetResponse and EndGetResponse methods.
The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the send data stream.
The HttpWebRequest class throws a WebException when an error occurs while accessing a resource. The WebException..::.Status property contains a WebExceptionStatus value that indicates the source of the error.
HttpWebRequest exposes common HTTP header values sent to the Internet resource as properties, set by methods, or set by the system; the following table contains a complete list. You can set other headers in the Headers property as name/value pairs. Note that servers and caches may change or add headers during the request.
The following table lists the HTTP headers that are set either by properties or methods or the system.
Header | Set by |
|---|
Accept | Set by the web browser that hosts the Silverlight application. |
Connection | Set by the web browser that hosts the Silverlight application. |
Content-Length | Set by the web browser that hosts the Silverlight application. |
Content-Type | Set by the ContentType property. This header cannot be set on a GET method. If this header is set, a ProtocolViolationException is thrown. |
Expect | Set by the web browser that hosts the Silverlight application. |
If-Modified-Since | Set by the web browser that hosts the Silverlight application. |
Referer | Set by the web browser that hosts the Silverlight application. |
Transfer-Encoding | Set by the web browser that hosts the Silverlight application. |
User-Agent | Set by the web browser that hosts the Silverlight application. |
The Item property can be used to set custom headers.
If the local computer configuration specifies that a proxy be used, or if the request specifies a proxy, the request is sent using the proxy. If no proxy is specified, the request is sent to the server.
Note: |
|---|
For security reasons, cookies are disabled by default. |
Silverlight version 2 and later includes support for cross-domain connectivity which allows an application to access resources from locations other than the site of origin. This is an important feature for enabling Silverlight applications to consume existing services on the web.
The security policy system in the Silverlight runtime requires that a policy file be downloaded from a network resource before a network connection is allowed access to that resource. This security policy system affects cross-domain network access for WebClient and HTTP classes in the System.Net namespace. Network connections for WebClient and HTTP classes to the site or host of origin do not require a security policy.
For security reasons, the Silverlight runtime restricts access to certain classes of URLs from the WebClient and HTTP classes in the System.Net namespace. There are similar access restrictions applied by the Silverlight runtime to other classes including the Image and MediaElement classes in the System.Windows.Controls namespace. The Silverlight runtime also applies access restrictions to XAML source files and font files based on the class of URL.
The connections affected are access to cross-zone, cross-domain, and cross-scheme URLs. These restrictions are designed to prevent networking threats (for example, threats based on a Silverlight application run from an internet server getting access to resources on a local intranet server).