Export (0) Print
Expand All
7 out of 10 rated this helpful - Rate this topic

WebRequest Class

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

Namespace:  System.Net
Assembly:  System (in System.dll)
[<AbstractClass>]
[<SerializableAttribute>]
type WebRequest =  
    class 
        inherit MarshalByRefObject 
        interface ISerializable 
    end

The WebRequest type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsWebRequest()Initializes a new instance of the WebRequest class.
Protected methodWebRequest(SerializationInfo, StreamingContext)Initializes a new instance of the WebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.
Top
  NameDescription
Public propertyAuthenticationLevelGets or sets values indicating the level of authentication and impersonation used for this request.
Public propertyCachePolicyGets or sets the cache policy for this request.
Public propertyConnectionGroupNameWhen overridden in a descendant class, gets or sets the name of the connection group for the request.
Public propertyContentLengthWhen overridden in a descendant class, gets or sets the content length of the request data being sent.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsContentTypeWhen overridden in a descendant class, gets or sets the content type of the request data being sent.
Public propertyCreatorInstance Obsolete. When 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 propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsCredentialsWhen overridden in a descendant class, gets or sets the network credentials used for authenticating the request with the Internet resource.
Public propertyStatic memberDefaultCachePolicyGets or sets the default cache policy for this request.
Public propertyStatic memberSupported in .NET for Windows Store appsDefaultWebProxyGets or sets the global HTTP proxy.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsHeadersWhen overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
Public propertyImpersonationLevelGets or sets the impersonation level for the current request.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsMethodWhen overridden in a descendant class, gets or sets the protocol method to use in this request.
Public propertyPreAuthenticateWhen overridden in a descendant class, indicates whether to pre-authenticate the request.
Public propertySupported in .NET for Windows Store appsProxyWhen overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsRequestUriWhen overridden in a descendant class, gets the URI of the Internet resource associated with the request.
Public propertyTimeoutGets or sets the length of time, in milliseconds, before the request times out.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsUseDefaultCredentialsWhen overridden in a descendant class, gets or sets a Boolean value that controls whether DefaultCredentials are sent with requests.
Top
  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAbortAborts the Request
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBeginGetRequestStreamWhen overridden in a descendant class, provides an asynchronous version of the GetRequestStream method.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBeginGetResponseWhen overridden in a descendant class, begins an asynchronous request for an Internet resource.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(String)Initializes a new WebRequest instance for the specified URI scheme.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(Uri)Initializes a new WebRequest instance for the specified URI scheme.
Public methodStatic memberCreateDefaultInitializes a new WebRequest instance for the specified URI scheme.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateHttp(String)Initializes a new HttpWebRequest instance for the specified URI string.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateHttp(Uri)Initializes a new HttpWebRequest instance for the specified URI.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEndGetRequestStreamWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEndGetResponseWhen overridden in a descendant class, returns a WebResponse.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetObjectDataInfrastructure. Populates a SerializationInfo with the data needed to serialize the target object.
Public methodGetRequestStreamWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource.
Public methodSupported in .NET for Windows Store appsGetRequestStreamAsyncWhen overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.
Public methodGetResponseWhen overridden in a descendant class, returns a response to an Internet request.
Public methodSupported in .NET for Windows Store appsGetResponseAsyncWhen overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.
Public methodStatic memberGetSystemWebProxyReturns a proxy configured with the Internet Explorer settings of the currently impersonated user.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodStatic memberRegisterPortableWebRequestCreator Obsolete. Register an IWebRequestCreate object.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsRegisterPrefixRegisters a WebRequest descendant for the specified URI.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Explicit interface implemetationPrivate methodISerializable.GetObjectDataInfrastructure. When overridden in a descendant class, populates a SerializationInfo instance with the data needed to serialize the WebRequest.
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 FTP, 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 WebExceptionStatus.ProtocolError, the Response property contains the WebResponse received from the Internet resource.

Because the WebRequest class is an abstract class, the actual behavior of WebRequest instances 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 and FileWebRequest.

NoteNote

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

NoteNote

If the application that creates the WebRequest object runs with the credentials of a Normal user, the application will not be able to access certificates installed in the local machine store unless permission has been explicitly given to the user to do so.

Notes to Inheritors

When you inherit from WebRequest, you must override the following members: Method, RequestUri, Headers, ContentLength, ContentType, Credentials, PreAuthenticate, GetRequestStream, BeginGetRequestStream, EndGetRequestStream, GetResponse, 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 or the configuration file.

The following example shows how to create a WebRequest instance and return the response.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
  • WebPermission 

    To access the requested URI or any URI that the request is redirected to. Associated enumeration: Connect.

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.