HttpListenerRequest クラス

定義

HttpListener オブジェクトに対する受信 HTTP 要求を記述します。 このクラスは継承できません。

public ref class HttpListenerRequest sealed
public sealed class HttpListenerRequest
type HttpListenerRequest = class
Public NotInheritable Class HttpListenerRequest
継承
HttpListenerRequest

次のコード例は、.HttpListenerRequest

// 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();
}
Public Shared Sub SimpleListenerExample(prefixes As String())
    If Not HttpListener.IsSupported Then
        Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.")
        Return
    End If
    ' URI prefixes are required,
    ' for example "http://contoso.com:8080/index/".
    If prefixes Is Nothing Or prefixes.Length = 0 Then
        Throw New ArgumentException("prefixes")
    End If

    ' Create a listener
    Dim listener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next
    listener.Start()
    Console.WriteLine("Listening...")
    ' Note: The GetContext method blocks while waiting for a request.
    Dim context As HttpListenerContext = listener.GetContext()
    Console.WriteLine("Listening...")
    ' Obtain a response object
    Dim request As HttpListenerRequest = context.Request
    ' Construct a response.
    Dim response As HttpListenerResponse = context.Response
    Dim responseString As String = "<HTML><BODY> Hello world!</BODY></HTML>"
    Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
    ' Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length
    Dim output As System.IO.Stream = response.OutputStream
    output.Write(buffer, 0, buffer.Length)
    'You must close the output stream.
    output.Close()
    listener.Stop()
End Sub

注釈

クライアントがオブジェクトによって処理される Uniform Resource Identifier (URI) に対して要求を HttpListener 行うと、 HttpListener クライアントに送信される送信者、要求、および応答に関する情報を含むオブジェクトが提供 HttpListenerContext されます。 このプロパティは HttpListenerContext.Request 、要求を HttpListenerRequest 記述するオブジェクトを返します。

オブジェクトにはHttpListenerRequest、要求文字列、文字列UserAgent、要求本文データなどの要求HttpMethodに関する情報が含まれています (プロパティをInputStream参照)。

要求に応答するには、プロパティを使用して関連付けられた応答を取得する Response 必要があります。

プロパティ

AcceptTypes

クライアントが受け入れる MIME の種類を取得します。

ClientCertificateError

クライアントから提供された X509Certificate の問題を識別するエラー コードを取得します。

ContentEncoding

要求と共に送信されるデータに使用できるコンテンツのエンコードを取得します。

ContentLength64

要求に含まれている本体データの長さを取得します。

ContentType

要求に含まれている本体データの MIME の種類を取得します。

Cookies

要求と共に送信されたクッキーを取得します。

HasEntityBody

要求に関連付けられている本体データがあるかどうかを示す Boolean 値を取得します。

Headers

要求で送信されるヘッダーの名前と値のペアのコレクションを取得します。

HttpMethod

クライアントによって指定された HTTP メソッドを取得します。

InputStream

クライアントから送信された本体データを格納しているストリームを取得します。

IsAuthenticated

この要求の送信元クライアントが認証されているかどうかを示す Boolean 値を取得します。

IsLocal

要求がローカル コンピューターから送信されたかどうかを示す Boolean 値を取得します。

IsSecureConnection

要求の送信に使用された TCP 接続が SSL (Secure Sockets Layer) プロトコルを使用しているかどうかを示す Boolean 値を取得します。

IsWebSocketRequest

TCP 接続が WebSocket 要求であったかどうかを示す Boolean 値を取得します。

KeepAlive

クライアントが永続的な接続を要求しているかどうかを示す Boolean 値を取得します。

LocalEndPoint

要求の転送先のサーバー IP アドレスおよびポート番号を取得します。

ProtocolVersion

要求元クライアントで使用されている HTTP のバージョンを取得します。

QueryString

要求に含まれているクエリ文字列を取得します。

RawUrl

クライアントによって要求された (ホストおよびポートを含まない) URL 情報を取得します。

RemoteEndPoint

要求の発行元の IP アドレスおよびポート番号を取得します。

RequestTraceIdentifier

受信 HTTP 要求の要求 ID を取得します。

ServiceName

クライアントが要求を送信したサービス プロバイダー名 (SPN: Service Provider Name) を取得します。

TransportContext

クライアント要求の TransportContext を取得します。

Url

クライアントによって要求された Uri オブジェクトを取得します。

UrlReferrer

クライアントをサーバーに導いたリソースの URI (Uniform Resource Identifier) を取得します。

UserAgent

クライアントによって示されたユーザー エージェントを取得します。

UserHostAddress

要求の転送先のサーバー IP アドレスおよびポート番号を取得します。

UserHostName

DNS 名とクライアントによって指定されたポート番号 (存在する場合) を取得します。

UserLanguages

応答への使用に適している自然言語を取得します。

メソッド

BeginGetClientCertificate(AsyncCallback, Object)

クライアントの X.509 v.3 証明書への非同期要求を開始します。

EndGetClientCertificate(IAsyncResult)

クライアントの X.509 v.3 証明書への非同期要求を終了します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetClientCertificate()

クライアントの X.509 v.3 証明書を取得します。

GetClientCertificateAsync()

クライアントの X.509 v.3 証明書を非同期操作として取得します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください