WebRequest Class

May 11, 2014

Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

'Declaration
Public MustInherit Class WebRequest

The WebRequest type exposes the following members.

  NameDescription
Protected methodWebRequestInitializes a new instance of the WebRequest class.
Top

  NameDescription
Public propertyContentLengthWhen overridden in a descendant class, gets or sets the content length of the request data being sent.
Public propertyContentTypeWhen overridden in a descendant class, gets or sets the content type of the request data being sent.
Public propertyCreatorInstanceWhen overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI.
Public propertyCredentialsWhen overridden in a descendant class, gets or sets the network credentials used for authenticating the request with the Internet resource.
Public propertyHeadersWhen overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
Public propertyMethodWhen overridden in a descendant class, gets or sets the protocol method to use in this request.
Public propertyRequestUriWhen overridden in a descendant class, gets the URI of the Internet resource associated with the request.
Public propertyUseDefaultCredentialsWhen overridden in a descendant class, gets or sets a Boolean value that controls whether default credentials are sent with requests.
Top

  NameDescription
Public methodAbortAborts the Request.
Public methodBeginGetRequestStreamWhen overridden in a descendant class, provides an asynchronous method to request a stream.
Public methodBeginGetResponseWhen overridden in a descendant class, begins an asynchronous request for an Internet resource.
Public methodStatic memberCreate(String)Initializes a new WebRequest instance for the specified URI scheme.
Public methodStatic memberCreate(Uri)Initializes a new WebRequest instance for the specified URI scheme.
Public methodStatic memberCreateHttp(String)Initializes a new HttpWebRequest instance for the specified URI string.
Public methodStatic memberCreateHttp(Uri)Initializes a new HttpWebRequest instance for the specified URI.
Public methodEndGetRequestStreamWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource.
Public methodEndGetResponseWhen overridden in a descendant class, returns a WebResponse.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetRequestStreamAsyncWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.
Public methodGetResponseAsyncWhen overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberRegisterPrefixRegisters a WebRequest descendant for the specified URI.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodGetCurrentNetworkInterfaceGets all available information about the network interface that corresponds to a web request. (Defined by WebRequestExtensions.)
Public Extension MethodSetNetworkPreferenceSets the preference for a web request to use either cellular or non-cellular technology. (Defined by WebRequestExtensions.)
Public Extension MethodSetNetworkRequirementSets the requirement for a web request to use either cellular or non-cellular technology. (Defined by WebRequestExtensions.)
Top

WebRequest is the abstract base class for the .NET Framework's request/response model for accessing data from the Internet. An application that uses the request/response model can request data from the Internet in a protocol-agnostic manner, in which the application works with instances of the WebRequest class while protocol-specific descendant classes carry out the details of the request.

Requests are sent from an application to a particular URI, such as a Web page on a server. The URI determines the proper descendant class to create from a list of WebRequest descendants registered for the application. WebRequest descendants are typically registered to handle a specific protocol, such as HTTP or HTTPS, but can be registered to handle a request to a specific server or path on a server.

The WebRequest class throws a WebException when errors occur while accessing an Internet resource. The Status property is one of the WebExceptionStatus values that indicates the source of the error.

When Status is UnknownError, additional details about the protocol specific response error may be available using the Response property. If the Response property is not null, this indicates that the remote server responded with an error code. In this case, the Response property can be queried for more specific information about the response.

Because the WebRequest class is an abstract class, the actual behavior of a WebRequest instance at run time is determined by the descendant class returned by Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest.

NoteNote:

Use the Create method to initialize new WebRequest instances. Do not use the WebRequest constructor.

Capabilities

If you use this API in your app, you must specify the following capabilities in the app manifest. Otherwise, your app might not work correctly or it might exit unexpectedly.

ID_CAP_NETWORKING

Windows Phone 8, Windows Phone OS 7.1

For more info, see App capabilities and hardware requirements for Windows Phone 8.

Notes to Inheritors

When you inherit from WebRequest, you must override the following members: Method, RequestUri, Headers, ContentType, Credentials, Abort, BeginGetRequestStream, EndGetRequestStream, BeginGetResponse, and EndGetResponse. In addition, you must provide an implementation of the IWebRequestCreate interface, which defines the Create method used when you call Create. You must register the class that implements the IWebRequestCreate interface, using the RegisterPrefix method.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2014 Microsoft