HttpWebRequest.ProtocolVersion-Eigenschaft
Ruft die für die Anforderung zu verwendende HTTP-Version ab oder legt diese fest.
Namespace: System.Net
Assembly: System (in system.dll)
Syntax
'Declaration
Public Property ProtocolVersion As Version
'Usage
Dim instance As HttpWebRequest
Dim value As Version
value = instance.ProtocolVersion
instance.ProtocolVersion = value
public Version ProtocolVersion { get; set; }
public:
property Version^ ProtocolVersion {
Version^ get ();
void set (Version^ value);
}
/** @property */
public Version get_ProtocolVersion ()
/** @property */
public void set_ProtocolVersion (Version value)
public function get ProtocolVersion () : Version
public function set ProtocolVersion (value : Version)
Eigenschaftenwert
Die für die Anforderung zu verwendende HTTP-Version. Der Standardwert ist HttpVersion.Version11.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Die HTTP-Version wurde auf einen anderen Wert als 1.0 oder 1.1 festgelegt. |
Hinweise
Die HttpWebRequest-Klasse unterstützt nur die HTTP-Versionen 1.0 und 1.1. Durch Festlegen von ProtocolVersion auf eine andere Version wird eine Ausnahme ausgelöst.
Hinweis
Um die HTTP-Version der aktuellen Anforderung festzulegen, verwenden Sie das Version10-Feld und das Version11-Feld der HttpVersion-Klasse.
Beispiel
Im folgenden Codebeispiel wird die ProtocolVersion-Eigenschaft festgelegt.
' Create a new 'HttpWebRequest' Object to the mentioned URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("https://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)
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("https://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( "https://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("https://www.microsoft.com");
// Use the existing 'ProtocolVersion' , and display it onto
// the console.
Console.WriteLine("\nThe 'ProtocolVersion' of the "
+"protocol used is {0}",
myHttpWebRequest.get_ProtocolVersion());
// Set the 'ProtocolVersion' property of the 'HttpWebRequest' to
// 'Version1.0'.
myHttpWebRequest.set_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.get_ProtocolVersion());
Console.WriteLine("\nThe protocol version of the response object"
+" is {0}", myHttpWebResponse.get_ProtocolVersion());
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
HttpWebRequest-Klasse
HttpWebRequest-Member
System.Net-Namespace