HttpWebResponse.ProtocolVersion 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得回應使用的 HTTP 通訊協定版本。
public:
property Version ^ ProtocolVersion { Version ^ get(); };
public Version ProtocolVersion { get; }
member this.ProtocolVersion : Version
Public ReadOnly Property ProtocolVersion As Version
屬性值
Version,包含回應的 HTTP 通訊協定版本。
例外狀況
目前的執行個體已經過處置。
範例
此範例會 HttpWebRequest 建立 的 和查詢 HttpWebResponse。 然後,此範例會檢查伺服器是否以相同的版本回應。
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.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();
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()
備註
屬性 ProtocolVersion 包含因特網資源所傳送之回應的 HTTP 通訊協定版本號碼。