HttpWebRequest.ProtocolVersion Properti

Definisi

Mendapatkan atau mengatur versi HTTP yang akan digunakan untuk permintaan.

public Version ProtocolVersion { get; set; }

Nilai Properti

Versi HTTP yang digunakan untuk permintaan. Defaultnya adalah Version11.

Pengecualian

Versi HTTP diatur ke nilai selain 1.0 atau 1.1.

Contoh

Contoh kode berikut mengatur Properti ProtocolVersion.

// 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);

Keterangan

Perhatian

WebRequest, HttpWebRequest, ServicePoint, dan WebClient usang, dan Anda tidak boleh menggunakannya untuk pengembangan baru. Gunakan HttpClient sebagai gantinya.

Kelas HttpWebRequest hanya mendukung HTTP versi 1.0 dan 1.1. Mengatur ProtocolVersion ke versi yang berbeda akan memberikan pengecualian.

Catatan

Untuk mengatur versi HTTP permintaan saat ini, gunakan bidang Version10 dan Version11 kelas HttpVersion.

Berlaku untuk

Produk Versi
.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