HttpWebResponse.ProtocolVersion-Eigenschaft
Ruft die in der Antwort verwendete Version des HTTP-Protokolls ab.
Namespace: System.Net
Assembly: System (in system.dll)
Syntax
'Declaration
Public ReadOnly Property ProtocolVersion As Version
'Usage
Dim instance As HttpWebResponse
Dim value As Version
value = instance.ProtocolVersion
public Version ProtocolVersion { get; }
public:
property Version^ ProtocolVersion {
Version^ get ();
}
/** @property */
public Version get_ProtocolVersion ()
public function get ProtocolVersion () : Version
Eigenschaftenwert
Eine Version mit der Version des HTTP-Protokolls der Antwort.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Die aktuelle Instanz wurde bereits verworfen. |
Hinweise
Die ProtocolVersion-Eigenschaft enthält die Versionsnummer des HTTP-Protokolls der von der Internetressource gesendeten Antwort.
Beispiel
In diesem Beispiel wird eine HttpWebRequest erstellt und eine HttpWebResponse abgefragt. Im Beispiel wird dann geprüft, ob der Server mit derselben Version antwortet.
Dim ourUri As New Uri(url)
' Creates an HttpWebRequest with the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(ourUri), HttpWebRequest)
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10
' Sends the request and waits for the response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'The ProtocolVersion property is used to ensure that only Http/1.0 responses are accepted.
If myHttpWebResponse.ProtocolVersion Is HttpVersion.Version10 Then
Console.WriteLine(ControlChars.NewLine + "The server responded with a version other than Http/1.0")
Else
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
Console.WriteLine(ControlChars.NewLine + "Request sent using version HTTP/1.0. Successfully received response with version Http/1.0 ")
End If
End If
' Releases the resources of the response.
myHttpWebResponse.Close()
Uri ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri);
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Ensures that only Http/1.0 responses are accepted.
if(myHttpWebResponse.ProtocolVersion != HttpVersion.Version10)
Console.WriteLine("\nThe server responded with a version other than Http/1.0");
else
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
Console.WriteLine("\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
// Releases the resources of the response.
myHttpWebResponse.Close();
Uri^ ourUri = gcnew Uri( url );
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( ourUri ) );
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
// Ensures that only Http/1.0 responses are accepted.
if ( myHttpWebResponse->ProtocolVersion != HttpVersion::Version10 )
{
Console::WriteLine( "\nThe server responded with a version other than Http/1.0" );
}
else if ( myHttpWebResponse->StatusCode == HttpStatusCode::OK )
{
Console::WriteLine( "\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 " );
}
// Releases the resources of the response.
myHttpWebResponse->Close();
Uri ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
WebRequest.Create(ourUri);
myHttpWebRequest.set_ProtocolVersion(HttpVersion.Version10);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
myHttpWebRequest.GetResponse();
// Ensures that only Http/1.0 responses are accepted.
if (!myHttpWebResponse.get_ProtocolVersion().
Equals(HttpVersion.Version10)) {
Console.WriteLine("\nThe server responded with a version "
+ "other than Http/1.0");
}
else {
if (myHttpWebResponse.get_StatusCode().
Equals(HttpStatusCode.OK)) {
Console.WriteLine("\nRequest sent using version Http/1.0. "
+ "Successfully received response with version "
+ "HTTP/1.0 ");
}
} // Releases the resources of the response.
myHttpWebResponse.Close();
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
HttpWebResponse-Klasse
HttpWebResponse-Member
System.Net-Namespace