HttpWebRequest.Timeout Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
ve GetRequestStream() yöntemleri için GetResponse() milisaniye cinsinden zaman aşımı değerini alır veya ayarlar.
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
Özellik Değeri
İstek zaman aşımına uğramadan önce beklenen milisaniye sayısı. Varsayılan değer 100.000 milisaniyedir (100 saniye).
Özel durumlar
Belirtilen değer sıfırdan küçük ve değil Infinite.
Örnekler
Aşağıdaki kod örneği, nesnesinin TimeoutHttpWebRequest özelliğini ayarlar.
// 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)
Açıklamalar
Timeout , yöntemiyle GetResponse yapılan sonraki bir zaman uyumlu isteğin yanıt beklediği ve GetRequestStream yöntemin akış beklediği milisaniye sayısıdır. , Timeout ve yöntemi çağrıları için ayrı ayrı değil, isteğin ve GetResponse yanıtın GetRequestStream tamamı için geçerlidir. Kaynak zaman aşımı süresi içinde döndürülmezse, istek özelliği olarak WebExceptionStatus.Timeoutayarlanmış bir WebExceptionStatus oluşturur.
Timeout veya GetResponse yöntemi çağrılmadan önce GetRequestStream özelliği ayarlanmalıdır. Timeout veya GetResponse yöntemini çağırdıktan sonra özelliğini değiştirmenin GetRequestStream hiçbir etkisi yoktur
Timeout özelliğinin veya BeginGetRequestStream yöntemiyle BeginGetResponse yapılan zaman uyumsuz istekler üzerinde hiçbir etkisi yoktur.
Dikkat
Zaman uyumsuz istekler söz konusu olduğunda, istemci uygulaması kendi zaman aşımı mekanizmasını uygular. yöntemindeki BeginGetResponse örne bakın.
Okuma veya yazma işlemi zaman aşımına uğramadan önce beklenme süresini belirtmek için özelliğini kullanın ReadWriteTimeout .
Etki Alanı Adı Sistemi (DNS) sorgusu döndürülmesi veya zaman aşımına uğrarken 15 saniye kadar sürebilir. İsteğiniz çözüm gerektiren bir ana bilgisayar adı içeriyorsa ve 15 saniyeden kısa bir değere ayarlarsanız Timeout , isteğinizin zaman aşımını belirtmesi 15 saniye veya daha uzun WebException sürebilir.
Şunlara uygulanır
Ayrıca bkz.
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin