HttpWebRequest.Timeout 속성

정의

GetResponse()GetRequestStream() 메서드의 제한 시간 값을 밀리초 단위로 가져오거나 설정합니다.

public:
 virtual property int Timeout { int get(); void set(int value); };
public override int Timeout { get; set; }
member this.Timeout : int with get, set
Public Overrides Property Timeout As Integer

속성 값

요청 시간이 초과되기 전에 대기할 시간(밀리초)입니다. 기본값은 100,000밀리초(100초)입니다.

예외

지정된 값이 0보다 작고 Infinite가 아닌 경우

예제

다음 코드 예제에서는 설정 합니다 Timeout 의 속성을 개체입니다 HttpWebRequest .

// 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.
     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)

설명

Timeout 는 메서드를 사용한 후속 동기 요청 GetResponse 이 응답을 대기하고 GetRequestStream 메서드가 스트림을 기다리는 시간(밀리초)입니다. 는 Timeout 및 메서드 호출에 개별적으로 적용되지 않고 전체 요청 및 GetResponse 응답에 GetRequestStream 적용됩니다. 리소스가 제한 시간 내에 반환되지 않으면 요청은 속성이 로 설정된 WebExceptionStatus.TimeoutStatus throw합니다WebException.

Timeout 또는 GetResponse 메서드가 호출되기 전에 GetRequestStream 속성을 설정해야 합니다. 또는 GetResponse 메서드를 호출한 TimeoutGetRequestStream 후 속성을 변경해도 아무런 영향을 주지 않습니다.

속성은 Timeout 또는 BeginGetRequestStream 메서드를 사용하여 수행한 BeginGetResponse 비동기 요청에 영향을 주지 않습니다.

주의

비동기 요청의 경우 클라이언트 애플리케이션 자체 제한 시간 메커니즘을 구현합니다. 메서드의 예제를 BeginGetResponse 참조하세요.

읽기 또는 쓰기 작업 시간이 초과되기 전에 대기할 시간을 지정하려면 속성을 사용합니다 ReadWriteTimeout .

DNS(도메인 이름 시스템) 쿼리는 반환하거나 시간 초과하는 데 최대 15초가 걸릴 수 있습니다. 요청에 확인이 필요한 호스트 이름이 포함되어 있고 15초 미만의 값으로 설정한 Timeout 경우 요청에 대한 시간 제한을 나타내기 위해 가 throw되기까지 WebException 15초 이상이 걸릴 수 있습니다.

적용 대상

추가 정보