HttpWebRequest.ProtocolVersion プロパティ
要求に対して使用する HTTP バージョンを取得または設定します。
Public Property ProtocolVersion As Version
[C#]
public Version ProtocolVersion {get; set;}
[C++]
public: __property Version* get_ProtocolVersion();public: __property void set_ProtocolVersion(Version*);
[JScript]
public function get ProtocolVersion() : Version;public function set ProtocolVersion(Version);
プロパティ値
要求に対して使用する HTTP バージョン。既定値は HttpVersion.Version11 です。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | HTTP バージョンが 1.0 または 1.1 以外の値に設定されています。 |
解説
HttpWebRequest クラスは、バージョン 1.0 およびバージョン 1.1 の HTTP だけをサポートしています。 ProtocolVersion をこれ以外のバージョンに設定すると、例外がスローされます。
メモ 現在の要求の HTTP バージョンを設定するには、 HttpVersion クラスの Version10 フィールドと Version11 フィールドを使用します。
使用例
[Visual Basic, C#, C++] ProtocolVersion プロパティを設定する例を次に示します。
' 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)
[C#]
// 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);
[C++]
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"https://www.microsoft.com"));
// Use the existing 'ProtocolVersion' , and display it onto the console.
Console::WriteLine(S"\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 =
dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
Console::WriteLine(S"\nThe 'ProtocolVersion' of the protocol changed to {0}",
myHttpWebRequest->ProtocolVersion);
Console::WriteLine(S"\nThe protocol version of the response Object* is {0}",
myHttpWebResponse->ProtocolVersion);
[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