次の方法で共有


HttpWebRequest.Timeout プロパティ

要求に対して使用するタイムアウト値を取得または設定します。

Overrides Public Property Timeout As Integer
[C#]
public override int Timeout {get; set;}
[C++]
public: __property int get_Timeout();public: __property void set_Timeout(int);
[JScript]
public override function get Timeout() : int;public override function set Timeout(int);

プロパティ値

要求がタイムアウトするまでのミリ秒単位の待機時間。

例外

例外の種類 条件
ArgumentOutOfRangeException 設定操作として指定した値が負で、 Infinite ではありませんでした。

解説

Timeout は、 GetResponse メソッドで行った同期要求が応答を待機する時間を表すミリ秒数です。 GetRequestStream メソッドは、ストリームを待機します。リソースがタイムアウト時間内に応答しない場合、要求は WebException をスローし、 Status プロパティを WebExceptionStatus.Timeout に設定します。

Timeout プロパティは、 BeginGetResponse メソッドまたは BeginGetRequestStream メソッドで行われた非同期要求には影響を与えません。

注意   非同期要求の場合は、クライアント側のアプリケーションが独自のタイムアウト機能を実装する必要があります。 BeginGetResponse メソッドの例を参照してください。

使用例

[Visual Basic, C#, C++] HttpWebRequest インスタンスの Timeout プロパティを設定する例を次に示します。

 
' Create a new 'HttpWebRequest' Object to the mentioned URL.
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("https://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 milli seconds.
        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)

[C#] 
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("https://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 milli seconds.
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();

[C++] 
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"https://www.contoso.com"));
Console::WriteLine(S"\nThe timeout time of the request before setting the property is {0} milliseconds.",
   __box(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(S"\nThe timeout time of the request after setting the timeout is {0} milliseconds.",
   __box(myHttpWebRequest->Timeout));
// A HttpWebResponse object is created and is GetResponse Property of the HttpWebRequest associated with it
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());

[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

参照

HttpWebRequest クラス | HttpWebRequest メンバ | System.Net 名前空間