HttpWebRequest.MaximumResponseHeadersLength Özellik

Tanım

Yanıt üst bilgilerinin izin verilen uzunluk üst sınırını alır veya ayarlar.

C#
public int MaximumResponseHeadersLength { get; set; }

Özellik Değeri

Yanıt üst bilgilerinin kilobayt (1024 bayt) cinsinden uzunluğu.

Özel durumlar

özellik, istek zaten gönderildikten sonra ayarlanır.

Değer 0'dan küçüktür.

Örnekler

Aşağıdaki kod örneği bu özelliğin değerini ayarlar.

C#
using System;
using System.Net;
using System.Text;
using System.IO;

    public class Test
    {
        // Specify the URL to receive the request.
        public static void Main (string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);

            // Set some reasonable limits on resources used by this request
            request.MaximumAutomaticRedirections = 4;
            request.MaximumResponseHeadersLength = 4;
            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Console.WriteLine("Content length is {0}", response.ContentLength);
            Console.WriteLine("Content type is {0}", response.ContentType);

            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream();

            // Pipes the stream to a higher level stream reader with the required encoding format.
            StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

            Console.WriteLine("Response stream received.");
            Console.WriteLine(readStream.ReadToEnd());
            response.Close();
            readStream.Close();
        }
    }

/*
The output from this example will vary depending on the value passed into Main
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/

Açıklamalar

Dikkat

WebRequest, HttpWebRequest, ServicePointve WebClient kullanım dışıdır ve bunları yeni geliştirme için kullanmamalısınız. Bunun yerine HttpClient kullanın.

Yanıt üst bilgisinin uzunluğu yanıt durumu satırını ve HTTP protokolünün bir parçası olarak alınan ek denetim karakterlerini içerir. 0 değeri, tüm isteklerin başarısız olduğu anlamına gelir.

MaximumResponseHeadersLength özelliği açıkça ayarlanmadıysa, varsayılan olarak DefaultMaximumResponseHeadersLength özelliğinin değerine ayarlanır.

Alınan yanıt üst bilgisinin uzunluğu MaximumResponseHeadersLength özelliğinin değerini aşarsa, EndGetResponse veya GetResponse yöntemleri Status özelliği MessageLengthLimitExceededolarak ayarlanmış bir WebException oluşturur.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1