Edit

Share via


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()

Source:
WebRequest.cs
Source:
WebRequest.cs
Source:
WebRequest.cs

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

Initializes a new instance of the WebRequest class.

C#
protected WebRequest();
C#
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected WebRequest();
Attributes

Examples

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

C#
WebRequest myRequest = WebRequest.Create("http://www.contoso.com");

Remarks

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

Applies to

.NET 9 and other versions
Product Versions (Obsolete)
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5 (6, 7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

WebRequest(SerializationInfo, StreamingContext)

Source:
WebRequest.cs
Source:
WebRequest.cs
Source:
WebRequest.cs

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

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

C#
protected WebRequest(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
C#
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are 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);

Parameters

serializationInfo
SerializationInfo

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.

Note

An application must run in full trust mode when using serialization.

See also

Applies to

.NET 9 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5 (6, 7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1