HttpWebRequest.ProtocolVersion Свойство

Определение

Возвращает или задает версию HTTP-протокола, используемую для запроса.

public:
 property Version ^ ProtocolVersion { Version ^ get(); void set(Version ^ value); };
public Version ProtocolVersion { get; set; }
member this.ProtocolVersion : Version with get, set
Public Property ProtocolVersion As Version

Значение свойства

Версия HTTP-протокола, используемая для запроса. Значение по умолчанию — Version11.

Исключения

Для версии HTTP задано значение, отличное от 1.0 или 1.1.

Примеры

В следующем примере кода задается 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 );
// 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);
' Create a new 'HttpWebRequest' Object to the mentioned URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)
' Use the existing 'ProtocolVersion' , and display it onto the console.	
Console.WriteLine(ControlChars.Cr + "The '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.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine(ControlChars.Cr + "The 'ProtocolVersion' of the protocol changed to {0}", myHttpWebRequest.ProtocolVersion)
Console.WriteLine(ControlChars.Cr + "The protocol version of the response object is {0}", myHttpWebResponse.ProtocolVersion)

Комментарии

Класс HttpWebRequest поддерживает только версии HTTP 1.0 и 1.1. При установке ProtocolVersion другой версии возникает исключение.

Примечание

Чтобы задать версию HTTP текущего запроса, используйте Version10 поля HttpVersion и Version11 класса .

Применяется к