HttpWebRequest.Timeout プロパティ
アセンブリ: System (system.dll 内)

Dim instance As HttpWebRequest Dim value As Integer value = instance.Timeout instance.Timeout = value
要求がタイムアウトするまでのミリ秒単位の待機時間。既定値は 100,000 ミリ秒 (100 秒) です。


Timeout は、GetResponse メソッドで行った後続の同期要求が応答を待機する時間を表すミリ秒数です。GetRequestStream メソッドは、ストリームを待機します。リソースがタイムアウト時間内に返されない場合、要求は WebException をスローし、Status プロパティを WebExceptionStatus.Timeout に設定します。
Timeout プロパティは、BeginGetResponse メソッドまたは BeginGetRequestStream メソッドで行われた非同期要求には影響を与えません。
![]() |
---|
非同期要求の場合は、クライアント アプリケーションが独自のタイムアウト機構を実装します。BeginGetResponse メソッドの例を参照してください。 |
読み取り操作または書き込み操作がタイムアウトするまでの待機時間を指定するには、ReadWriteTimeout プロパティを使用します。
ドメイン ネーム システム (DNS: Domain Name System) クエリが値を返すか、タイムアウトするまでに、最大で 15 秒かかることがあります。解決する必要があるホスト名が要求に含まれている場合、Timeout を 15 秒未満の値に設定していても、要求のタイムアウトを示す WebException がスローされるまでに 15 秒以上かかることがあります。

HttpWebRequest オブジェクトの Timeout プロパティを設定するコード例を次に示します。
' Create a new 'HttpWebRequest' Object to the mentioned URL. Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.contoso.com"), HttpWebRequest) Console.WriteLine(ControlChars.Cr + "The timeout time of the request before setting the property is {0} milliSeconds", myHttpWebRequest.Timeout) ' Set the 'Timeout' property of the HttpWebRequest to 10 milliseconds. myHttpWebRequest.Timeout = 10 ' Display the 'Timeout' property of the 'HttpWebRequest' on the console. Console.WriteLine(ControlChars.Cr + "The timeout time of the request after setting the timeout is {0} milliSeconds", myHttpWebRequest.Timeout) ' A HttpWebResponse object is created and is GetResponse Property of the HttpWebRequest associated with it Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
// Create a new 'HttpWebRequest' Object to the mentioned URL. HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com"); Console.WriteLine("\nThe timeout time of the request before setting the property is {0} milliSeconds.",myHttpWebRequest.Timeout); // Set the 'Timeout' property of the HttpWebRequest to 10 milliseconds. myHttpWebRequest.Timeout=10; // Display the 'Timeout' property of the 'HttpWebRequest' on the console. Console.WriteLine("\nThe timeout time of the request after setting the timeout is {0} milliSeconds.",myHttpWebRequest.Timeout); // A HttpWebResponse object is created and is GetResponse Property of the HttpWebRequest associated with it HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
// Create a new 'HttpWebRequest' Object to the mentioned URL. HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) ); Console::WriteLine( "\nThe timeout time of the request before setting the property is {0} milliseconds.", myHttpWebRequest->Timeout ); // Set the 'Timeout' property of the HttpWebRequest to 10 milliseconds. myHttpWebRequest->Timeout = 10; // Display the 'Timeout' property of the 'HttpWebRequest' on the console. Console::WriteLine( "\nThe timeout time of the request after setting the timeout is {0} milliseconds.", myHttpWebRequest->Timeout ); // A HttpWebResponse object is created and is GetResponse Property of the HttpWebRequest associated with it HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
// Create a new 'HttpWebRequest' Object to the mentioned URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.contoso.com"); Console.WriteLine("\nThe timeout time of the request before" + " setting the property is {0} milliSeconds.", System.Convert.ToString(myHttpWebRequest.get_Timeout())); // Set the 'Timeout' property of the HttpWebRequest to 10 milli // seconds. myHttpWebRequest.set_Timeout(10); // Display the 'Timeout' property of the 'HttpWebRequest' on // the console. Console.WriteLine("\nThe timeout time of the request after setting" + " the timeout is {0} milliSeconds.", System.Convert.ToString(myHttpWebRequest.get_Timeout())); // A HttpWebResponse object is created and is GetResponse Property //of the HttpWebRequest associated with it HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpWebRequest.Timeout プロパティを検索する場合は、下記のリンクをクリックしてください。

- HttpWebRequest.Timeout プロパティのページへのリンク