次の方法で共有


HttpWebRequest.MaximumResponseHeadersLength プロパティ

メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。

応答ヘッダーの許容最大長を取得または設定します。

Public Property MaximumResponseHeadersLength As Integer
[C#]
public int MaximumResponseHeadersLength {get; set;}
[C++]
public: __property int get_MaximumResponseHeadersLength();public: __property void set_MaximumResponseHeadersLength(int);
[JScript]
public function get MaximumResponseHeadersLength() : int;public function set MaximumResponseHeadersLength(int);

プロパティ値

応答ヘッダーの長さ (KB 単位、1 KB = 1024 バイト)。

例外

例外の種類 条件
InvalidOperationException このプロパティは、要求の送信後に設定されます。
ArgumentOutOfRangeException 値が 0 未満で、-1 と等しくありません。

解説

長さは KB (1024 バイト) 単位で示されます。この長さには、応答のステータス ラインと応答ヘッダー、および HTTP プロトコルの一部として受信する補足的な制御文字すべてが含まれます。値 -1 は、こうした制限が応答ヘッダーに設定されていないこと、値 0 は、すべての要求が失敗することを意味します。

使用例

[Visual Basic, C#] このプロパティの値を設定する例を次に示します。

 
Imports System
Imports System.Net
Imports System.Text
Imports System.IO


    Public Class Test

        ' Specify the URL to receive the request.
        Public Shared Sub Main(ByVal args() As String)
        Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)), HttpWebRequest)


        ' 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

        Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

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

        ' Get the stream associated with the response.
        Dim receiveStream As Stream = response.GetResponseStream()

        ' Pipes the stream to a higher level stream reader with the required encoding format. 
        Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)

        Console.WriteLine("Response stream received.")
        Console.WriteLine(readStream.ReadToEnd())
        response.Close()
        readStream.Close()
    End Sub 'Main
End Class 'Test
'
'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>
'
'

[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>

*/

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

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