HttpWebResponse.ProtocolVersion プロパティ
応答で使用される HTTP プロトコルのバージョンを取得します。
Public ReadOnly Property ProtocolVersion As Version
[C#]
public Version ProtocolVersion {get;}
[C++]
public: __property Version* get_ProtocolVersion();
[JScript]
public function get ProtocolVersion() : Version;
プロパティ値
応答の HTTP プロトコルのバージョンを格納している Version 。
例外
例外の種類 | 条件 |
---|---|
ObjectDisposedException | 現在のインスタンスは破棄されています。 |
解説
ProtocolVersion プロパティは、インターネット リソースから送信された応答の HTTP プロトコルのバージョン番号を格納します。
使用例
[Visual Basic, C#, C++] この例では、 HttpWebRequest を作成し、 HttpWebResponse を問い合わせます。この例では、次に、サーバーが同じバージョンで応答するかどうかを確認します。
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()
[C#]
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();
[C++]
Uri* ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(ourUri));
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse* myHttpWebResponse =
dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
// Ensures that only Http/1.0 responses are accepted.
if (myHttpWebResponse->ProtocolVersion != HttpVersion::Version10)
Console::WriteLine(S"\nThe server responded with a version other than Http/1.0");
else
if (myHttpWebResponse->StatusCode == HttpStatusCode::OK)
Console::WriteLine(S"\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
// Releases the resources of the response.
myHttpWebResponse->Close();
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard