WebRequest Constructors

Definition

Initializes a new instance of the WebRequest class.

Overloads

WebRequest()
Obsolete.

Initializes a new instance of the WebRequest class.

WebRequest(SerializationInfo, StreamingContext)
Obsolete.

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

WebRequest()

Caution

Use HttpClient instead.

Initializes a new instance of the WebRequest class.

protected:
 WebRequest();
protected WebRequest ();
[System.Obsolete("Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WebRequest ();
Protected Sub New ()
Attributes

Examples

The following example shows how to create a WebRequest instance by calling the Create method on the WebRequest class.

WebRequest^ myRequest = WebRequest::Create( "http://www.contoso.com" );
WebRequest myRequest = WebRequest.Create("http://www.contoso.com");
Dim myRequest As WebRequest = WebRequest.Create("http://www.contoso.com")

Remarks

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

Applies to

WebRequest(SerializationInfo, StreamingContext)

Caution

Use HttpClient instead.

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

protected:
 WebRequest(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected WebRequest (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
[System.Obsolete("Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WebRequest (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
new System.Net.WebRequest : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebRequest
[<System.Obsolete("Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Net.WebRequest : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Net.WebRequest
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)

Parameters

serializationInfo
SerializationInfo

A SerializationInfo that contains the information required to serialize the new WebRequest instance.

streamingContext
StreamingContext

A StreamingContext that indicates the source of the serialized stream associated with the new WebRequest instance.

Attributes

Exceptions

Any attempt is made to access the constructor, when the constructor is not overridden in a descendant class.

Remarks

When implemented by a descendant class, this constructor implements the ISerializable interface for the WebRequest descendant.

Notice that an application must run in full trust mode when using serialization.

Applies to