WebHeaderCollection.IsRestricted Método

Definición

Comprueba si se puede establecer el encabezado HTTP especificado.

Sobrecargas

Nombre Description
IsRestricted(String)

Comprueba si se puede establecer el encabezado HTTP especificado para la solicitud.

IsRestricted(String, Boolean)

Comprueba si el encabezado HTTP especificado se puede establecer para la solicitud o la respuesta.

IsRestricted(String)

Comprueba si se puede establecer el encabezado HTTP especificado para la solicitud.

public:
 static bool IsRestricted(System::String ^ headerName);
public static bool IsRestricted(string headerName);
static member IsRestricted : string -> bool
Public Shared Function IsRestricted (headerName As String) As Boolean

Parámetros

headerName
String

Encabezado que se va a probar.

Devoluciones

true si el encabezado está restringido; de lo contrario false, es .

Excepciones

headerName es null o Empty.

headerName contiene caracteres no válidos.

Ejemplos

En el ejemplo siguiente se comprueba la IsRestricted propiedad para ver si se establece algún encabezado.

    try {
        // Create a web request for "www.msn.com".
        HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.msn.com");

        // Get the associated response for the above request.
        HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();

        // Get the headers associated with the response.
        WebHeaderCollection myWebHeaderCollection = myHttpWebResponse.Headers;
        
        for (int i = 0; i < myWebHeaderCollection.Count;i++)	
        {
        // Check if the first response header is restricted.
        if(WebHeaderCollection.IsRestricted(myWebHeaderCollection.AllKeys[i]))
            Console.WriteLine("'{0}' is a restricted header", myWebHeaderCollection.AllKeys[i]);
        else
            Console.WriteLine("'{0}' is not a restricted header", myWebHeaderCollection.AllKeys[i]);
        }
        myHttpWebResponse.Close();
    }
    catch(WebException e) {
        Console.WriteLine("\nWebException is thrown.\nMessage is:" + e.Message);
        if(e.Status == WebExceptionStatus.ProtocolError) {
            Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
            Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
            Console.WriteLine("Server : {0}", ((HttpWebResponse)e.Response).Server);
        }
    }
    catch(Exception e) {
        Console.WriteLine("Exception is thrown. Message is :" + e.Message);
    }
}
Public Shared Sub Main()
Try
        'Create a web request for "www.msn.com".
        Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
        
        'Get the associated response for the above request.
        Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
        
        'Get the headers associated with the response.
        Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebResponse.Headers
        
        'Check if the first response header is restricted.
    dim i as integer
    for i =0 to myWebHeaderCollection.Count-1
            If WebHeaderCollection.IsRestricted(myWebHeaderCollection.AllKeys(i)) Then
                Console.WriteLine("'{0}' is a restricted header", myWebHeaderCollection.AllKeys(i))
            Else
                Console.WriteLine("'{0}' is not a restricted header", myWebHeaderCollection.AllKeys(i))
            End If 
    next
    myHttpWebResponse.Close()
    Catch e As WebException
        Console.WriteLine(e.Message)
        If e.Status = WebExceptionStatus.ProtocolError Then
            Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
            Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
            Console.WriteLine("Server : {0}", CType(e.Response, HttpWebResponse).Server)
        End If
    Catch e As Exception
        Console.WriteLine(e.Message)
    End Try
End Sub

Comentarios

El IsRestricted método devuelve true para indicar que un encabezado está restringido y debe establecerse mediante propiedades en lugar de directamente o se establece mediante el sistema. Los encabezados restringidos son:

  • Aceptar

  • Conexión

  • Longitud del contenido

  • Tipo de contenido

  • Date

  • Esperar

  • Host

  • If-Modified-Since

  • Alcance

  • Referencia

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

Se aplica a

IsRestricted(String, Boolean)

Comprueba si el encabezado HTTP especificado se puede establecer para la solicitud o la respuesta.

public:
 static bool IsRestricted(System::String ^ headerName, bool response);
public static bool IsRestricted(string headerName, bool response);
static member IsRestricted : string * bool -> bool
Public Shared Function IsRestricted (headerName As String, response As Boolean) As Boolean

Parámetros

headerName
String

Encabezado que se va a probar.

response
Boolean

true para probar la respuesta; false para probar la solicitud.

Devoluciones

true si el encabezado está restringido; de lo contrario, false.

Excepciones

headerName es null o Empty.

headerName contiene caracteres no válidos.

Ejemplos

En el ejemplo siguiente se comprueba la IsRestricted propiedad para ver si se prohíbe establecer algún encabezado de solicitud.

    try {
        // Create a web request for "www.msn.com".
        HttpWebRequest myHttpWebRequest = (HttpWebRequest) WebRequest.Create("http://www.msn.com");

        // Get the associated response for the above request.
        HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();

        // Get the headers associated with the response.
        WebHeaderCollection myWebHeaderCollection = myHttpWebResponse.Headers;
        
        for (int i = 0; i < myWebHeaderCollection.Count;i++)	
        {
        // Check if the first response header is restricted.
        if(WebHeaderCollection.IsRestricted(myWebHeaderCollection.AllKeys[i]))
            Console.WriteLine("'{0}' is a restricted header", myWebHeaderCollection.AllKeys[i]);
        else
            Console.WriteLine("'{0}' is not a restricted header", myWebHeaderCollection.AllKeys[i]);
        }
        myHttpWebResponse.Close();
    }
    catch(WebException e) {
        Console.WriteLine("\nWebException is thrown.\nMessage is:" + e.Message);
        if(e.Status == WebExceptionStatus.ProtocolError) {
            Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
            Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
            Console.WriteLine("Server : {0}", ((HttpWebResponse)e.Response).Server);
        }
    }
    catch(Exception e) {
        Console.WriteLine("Exception is thrown. Message is :" + e.Message);
    }
}
Public Shared Sub Main()
Try
        'Create a web request for "www.msn.com".
        Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
        
        'Get the associated response for the above request.
        Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
        
        'Get the headers associated with the response.
        Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebResponse.Headers
        
        'Check if the first response header is restricted.
    dim i as integer
    for i =0 to myWebHeaderCollection.Count-1
            If WebHeaderCollection.IsRestricted(myWebHeaderCollection.AllKeys(i)) Then
                Console.WriteLine("'{0}' is a restricted header", myWebHeaderCollection.AllKeys(i))
            Else
                Console.WriteLine("'{0}' is not a restricted header", myWebHeaderCollection.AllKeys(i))
            End If 
    next
    myHttpWebResponse.Close()
    Catch e As WebException
        Console.WriteLine(e.Message)
        If e.Status = WebExceptionStatus.ProtocolError Then
            Console.WriteLine("Status Code : {0}", CType(e.Response, HttpWebResponse).StatusCode)
            Console.WriteLine("Status Description : {0}", CType(e.Response, HttpWebResponse).StatusDescription)
            Console.WriteLine("Server : {0}", CType(e.Response, HttpWebResponse).Server)
        End If
    Catch e As Exception
        Console.WriteLine(e.Message)
    End Try
End Sub

Comentarios

El IsRestricted método devuelve true para indicar que un encabezado de solicitud o respuesta está restringido y debe establecerse mediante propiedades en lugar de directamente o se establece por el sistema. Los encabezados restringidos son:

  • Aceptar

  • Conexión

  • Longitud del contenido

  • Tipo de contenido

  • Date

  • Esperar

  • Host

  • If-Modified-Since

  • Alcance

  • Referencia

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

Se aplica a