HttpListenerPrefixCollection.Add メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpListenerPrefixCollection.Add メソッドの意味・解説 

HttpListenerPrefixCollection.Add メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

コレクションURI プレフィックス追加します

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

Public Sub Add ( _
    uriPrefix As String _
)
Dim instance As HttpListenerPrefixCollection
Dim uriPrefix As String

instance.Add(uriPrefix)
public void Add (
    string uriPrefix
)
public final void Add (
    String uriPrefix
)

パラメータ

uriPrefix

受信要求比較される URI 情報識別する Stringプレフィックスは、スラッシュ ("/") で終了する必要があります

例外例外
例外種類条件

ArgumentNullException

uriPrefixnull 参照 (Visual Basic では Nothing) です。

ArgumentException

uriPrefix が、http:// または https:// スキーム使用していません。HttpListener オブジェクトでは、これらのスキームのみがサポートされています。

または

uriPrefix が、正し書式URI プレフィックスではありません。文字列は必ず "/" で終わる必要があります

ObjectDisposedException

このコレクション関連付けられている HttpListener閉じてます。

HttpListenerException

Windows 関数呼び出し失敗しました例外ErrorCode プロパティチェックして例外原因確認してください。この例外は、別の HttpListener が既にプレフィックス uriPrefix追加している場合スローさます。

解説解説

このメソッドは、関連付けられた HttpListener オブジェクトによって管理されているプレフィックスセットに、URI プレフィックス追加しますuriPrefixチェックして有効であることを確認しているときは、大文字と小文字区別無視されます。

URI プレフィックス文字列は、"http://www.contoso.com:8080/customerData/" のように、スキーム (http または https)、ホストポート (省略可能)、およびパス (省略可能) で構成されます。プレフィックスは、スラッシュ ("/") で終了する必要があります要求されURI に最も一致するプレフィックスを持つ HttpListener要求応答します。複数HttpListener オブジェクトが同じプレフィックス追加することはできません。既に使用中プレフィックスHttpListener追加した場合は、HttpListenerException 例外スローさます。

ポート指定されている場合ホスト要素を "*" に置き換えて要求されURI が他のプレフィックス一致しない場合HttpListener がそのポート送信され要求受け入れることを示すことができます。たとえば、要求されURI が他のどの HttpListener でも処理されない場合に、ポート 8080送信されすべての要求受信するようにするには、プレフィックスを "http://*:8080/" にします。同様にHttpListener が、あるポート送信されすべての要求受け入れることを指定するには、ホスト要素を "+" という文字置き換えて、"https://+:8080/" のようにします。"*" および "+" の文字は、パス含んだプレフィックス使用できます

使用例使用例

HttpListener作成し、その HttpListenerPrefixCollection にユーザー指定プレフィックス追加するコード例次に示します

// 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();
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpListenerPrefixCollection クラス
HttpListenerPrefixCollection メンバ
System.Net 名前空間
HttpListener クラス


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpListenerPrefixCollection.Add メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpListenerPrefixCollection.Add メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpListenerPrefixCollection.Add メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpListenerPrefixCollection.Add メソッドのお隣キーワード
検索ランキング

   

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



HttpListenerPrefixCollection.Add メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS