HttpListenerResponse.ContentLength64 プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpListenerResponse.ContentLength64 プロパティの意味・解説 

HttpListenerResponse.ContentLength64 プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

応答に含まれている本体データのバイト数を取得または設定します。

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Property ContentLength64 As
 Long
Dim instance As HttpListenerResponse
Dim value As Long

value = instance.ContentLength64

instance.ContentLength64 = value
public long ContentLength64 { get; set;
 }
/** @property */
public long get_ContentLength64 ()

/** @property */
public void set_ContentLength64 (long value)
public function get ContentLength64
 () : long

public function set ContentLength64
 (value : long)

プロパティ値
応答の Content-Length ヘッダーの値。

例外例外
例外の種類条件

ArgumentOutOfRangeException

設定操作に指定された値が 0 未満です。

InvalidOperationException

この応答は既に送信されています。

ObjectDisposedException

オブジェクトが閉じています。

解説解説

Content-Length ヘッダーは、応答の本体データの長さをバイト単位で表します。 System.Net.EntitySendFormat.ContentLength の送信形式を使用する場合は、ContentLength64 プロパティを設定する必要があります。そうしないと、HttpListener は応答データを送信しません。

応答ヘッダーの完全な一覧については、HttpResponseHeader 列挙体を参照してください。

使用例使用例

このプロパティの値を設定するコード例を次に示します。

// This example requires the System and System.Net namespaces.
public static void SimpleListenerExample(string[]
 prefixes)
{
    if (!HttpListener.IsSupported)
    {
        Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use
 the HttpListener class.");
        return;
    }
    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length
 == 0)
      throw new ArgumentException("prefixes");
    
    // Create a listener.
    HttpListener listener = new HttpListener();
    // Add the prefixes.
    foreach (string s in
 prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    Console.WriteLine("Listening...");
    // Note: The GetContext method blocks while waiting for a request.
 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response.
    string responseString = "<HTML><BODY> Hello
 world!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    output.Write(buffer,0,buffer.Length);
    // You must close the output stream.
    output.Close();
    listener.Stop();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpListenerResponse クラス
HttpListenerResponse メンバ
System.Net 名前空間
HttpListener クラス
HttpListenerContext クラス
HttpListenerRequest クラス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

HttpListenerResponse.ContentLength64 プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpListenerResponse.ContentLength64 プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS