WebRequest Class
TOC
Collapse the table of content
Expand the table of content

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

NameDescription
System_CAPS_protmethodWebRequest()

Initializes a new instance of the WebRequest class.

System_CAPS_protmethodWebRequest(SerializationInfo, StreamingContext)

Initializes a new instance of the WebRequest class from the specified instances of the SerializationInfo and StreamingContext classes.

NameDescription
System_CAPS_pubpropertyAuthenticationLevel

Gets or sets values indicating the level of authentication and impersonation used for this request.

System_CAPS_pubpropertyCachePolicy

Gets or sets the cache policy for this request.

System_CAPS_pubpropertyConnectionGroupName

When overridden in a descendant class, gets or sets the name of the connection group for the request.

System_CAPS_pubpropertyContentLength

When overridden in a descendant class, gets or sets the content length of the request data being sent.

System_CAPS_pubpropertyContentType

When overridden in a descendant class, gets or sets the content type of the request data being sent.

System_CAPS_pubpropertyCreatorInstance

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.

System_CAPS_pubpropertyCredentials

When overridden in a descendant class, gets or sets the network credentials used for authenticating the request with the Internet resource.

System_CAPS_pubpropertySystem_CAPS_staticDefaultCachePolicy

Gets or sets the default cache policy for this request.

System_CAPS_pubpropertySystem_CAPS_staticDefaultWebProxy

Gets or sets the global HTTP proxy.

System_CAPS_pubpropertyHeaders

When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.

System_CAPS_pubpropertyImpersonationLevel

Gets or sets the impersonation level for the current request.

System_CAPS_pubpropertyMethod

When overridden in a descendant class, gets or sets the protocol method to use in this request.

System_CAPS_pubpropertyPreAuthenticate

When overridden in a descendant class, indicates whether to pre-authenticate the request.

System_CAPS_pubpropertyProxy

When overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.

System_CAPS_pubpropertyRequestUri

When overridden in a descendant class, gets the URI of the Internet resource associated with the request.

System_CAPS_pubpropertyTimeout

Gets or sets the length of time, in milliseconds, before the request times out.

System_CAPS_pubpropertyUseDefaultCredentials

When overridden in a descendant class, gets or sets a Boolean value that controls whether DefaultCredentials are sent with requests.

NameDescription
System_CAPS_pubmethodAbort()

Aborts the Request

System_CAPS_pubmethodBeginGetRequestStream(AsyncCallback, Object)

When overridden in a descendant class, provides an asynchronous version of the GetRequestStream method.

System_CAPS_pubmethodBeginGetResponse(AsyncCallback, Object)

When overridden in a descendant class, begins an asynchronous request for an Internet resource.

System_CAPS_pubmethodSystem_CAPS_staticCreate(String)

Initializes a new WebRequest instance for the specified URI scheme.

System_CAPS_pubmethodSystem_CAPS_staticCreate(Uri)

Initializes a new WebRequest instance for the specified URI scheme.

System_CAPS_pubmethodSystem_CAPS_staticCreateDefault(Uri)

Initializes a new WebRequest instance for the specified URI scheme.

System_CAPS_pubmethodSystem_CAPS_staticCreateHttp(String)

Initializes a new HttpWebRequest instance for the specified URI string.

System_CAPS_pubmethodSystem_CAPS_staticCreateHttp(Uri)

Initializes a new HttpWebRequest instance for the specified URI.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodEndGetRequestStream(IAsyncResult)

When overridden in a descendant class, returns a Stream for writing data to the Internet resource.

System_CAPS_pubmethodEndGetResponse(IAsyncResult)

When overridden in a descendant class, returns a WebResponse.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodGetObjectData(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Populates a SerializationInfo with the data needed to serialize the target object.

System_CAPS_pubmethodGetRequestStream()

When overridden in a descendant class, returns a Stream for writing data to the Internet resource.

System_CAPS_pubmethodGetRequestStreamAsync()

When overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.

System_CAPS_pubmethodGetResponse()

When overridden in a descendant class, returns a response to an Internet request.

System_CAPS_pubmethodGetResponseAsync()

When overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.

System_CAPS_pubmethodSystem_CAPS_staticGetSystemWebProxy()

Returns a proxy configured with the Internet Explorer settings of the currently impersonated user.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodSystem_CAPS_staticRegisterPortableWebRequestCreator(IWebRequestCreate)

Obsolete.Register an IWebRequestCreate object.

System_CAPS_pubmethodSystem_CAPS_staticRegisterPrefix(String, IWebRequestCreate)

Registers a WebRequest descendant for the specified URI.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodISerializable.GetObjectData(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. When overridden in a descendant class, populates a SerializationInfo instance with the data needed to serialize the WebRequest.

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.

System_CAPS_noteNote

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

System_CAPS_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.

WebPermission

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

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

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

Return to top
Show:
© 2016 Microsoft