Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
Biblioteca de clases de .NET Framework
HttpListenerContext.Request (Propiedad)

Nota: esta propiedad es nueva en la versión 2.0 de .NET Framework.

Obtiene la clase HttpListenerRequest que representa la solicitud de un cliente para un recurso.

Espacio de nombres: System.Net
Ensamblado: System (en system.dll)

Visual Basic (Declaración)
Public ReadOnly Property Request As HttpListenerRequest
Visual Basic (Uso)
Dim instance As HttpListenerContext
Dim value As HttpListenerRequest

value = instance.Request
C#
public HttpListenerRequest Request { get; }
C++
public:
property HttpListenerRequest^ Request {
    HttpListenerRequest^ get ();
}
J#
/** @property */
public HttpListenerRequest get_Request ()
JScript
public function get Request () : HttpListenerRequest

Valor de propiedad

Un objeto HttpListenerRequest que representa la solicitud de cliente.

Si cierra este objeto HttpListenerContext, se enviará la respuesta al cliente, se cerrará la clase HttpListenerResponse que contiene la respuesta y se cerrará el objeto HttpListenerRequest devuelto por esta propiedad.

Nota de la plataforma Windows XP Home, Windows XP Professional x64, Windows Server 2003: Se requiere Service Pack 2 para utilizar la clase HttpListener.

Nota de la plataforma Windows Server 2003: Admite el uso de la clase HttpListener.

En el ejemplo de código siguiente se muestra la forma de llamar a este método. La variable listener contiene un objeto HttpListener.

C#
// This example requires the System and System.Net namespaces.
public static string ClientInformation(HttpListenerContext context)
{
    System.Security.Principal.IPrincipal user = context.User;
    System.Security.Principal.IIdentity id = user.Identity;
    if (id == null)
    {
        return "Client authentication is not enabled for this Web server.";
    }
    
    string display;
    if (id.IsAuthenticated)
    {
        display = String.Format("{0} was authenticated using {1}", id.Name, 
            id.AuthenticationType);
    }
    else
    {
       display = String.Format("{0} was not authenticated", id.Name);
    }
    return display;
}

public static void SimpleListenerWithAuthentication(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");

    // Set up a listener.
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    // Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
    Console.WriteLine("Listening...");
    // GetContext 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 clientInformation = ClientInformation(context);
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes("<HTML><BODY> " + clientInformation + "</BODY></HTML>");
    // 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);
    output.Close();
    listener.Stop();
}

Windows 98, Windows Server 2003, Windows XP Media Center, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker