HttpWebRequest.ProtocolVersion Özellik

Tanım

İstek için kullanılacak HTTP sürümünü alır veya ayarlar.

C#
public Version ProtocolVersion { get; set; }

Özellik Değeri

İstek için kullanılacak HTTP sürümü. Varsayılan değer Version11.

Özel durumlar

HTTP sürümü 1.0 veya 1.1 dışında bir değere ayarlanır.

Örnekler

Aşağıdaki kod örneği ProtocolVersion Özelliğini ayarlar.

C#
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
// Use the existing 'ProtocolVersion' , and display it onto the console.	
Console.WriteLine("\nThe 'ProtocolVersion' of the protocol used is {0}",myHttpWebRequest.ProtocolVersion);
// Set the 'ProtocolVersion' property of the 'HttpWebRequest' to 'Version1.0' .
myHttpWebRequest.ProtocolVersion=HttpVersion.Version10;
 // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
 HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("\nThe 'ProtocolVersion' of the protocol changed to {0}",myHttpWebRequest.ProtocolVersion);
Console.WriteLine("\nThe protocol version of the response object is {0}",myHttpWebResponse.ProtocolVersion);

Açıklamalar

Dikkat

WebRequest, HttpWebRequest, ServicePointve WebClient kullanım dışıdır ve bunları yeni geliştirme için kullanmamalısınız. Bunun yerine HttpClient kullanın.

HttpWebRequest sınıfı yalnızca HTTP'nin 1.0 ve 1.1 sürümlerini destekler. ProtocolVersion farklı bir sürüme ayarlanması özel durum oluşturur.

Not

Geçerli isteğin HTTP sürümünü ayarlamak için HttpVersion sınıfının Version10 ve Version11 alanlarını kullanın.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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