Sdílet prostřednictvím


WebHeaderCollection.IsRestricted Metoda

Definice

Testuje, jestli je možné nastavit zadanou hlavičku HTTP.

Přetížení

IsRestricted(String)

Testuje, jestli je možné pro požadavek nastavit zadanou hlavičku HTTP.

IsRestricted(String, Boolean)

Testuje, jestli je možné pro požadavek nebo odpověď nastavit zadanou hlavičku HTTP.

IsRestricted(String)

Zdroj:
WebHeaderCollection.cs
Zdroj:
WebHeaderCollection.cs
Zdroj:
WebHeaderCollection.cs

Testuje, jestli je možné pro požadavek nastavit zadanou hlavičku HTTP.

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

Parametry

headerName
String

Hlavička, která se má testovat.

Návraty

true pokud je hlavička omezena; jinak false.

Výjimky

headerName je null nebo Empty.

headerName obsahuje neplatné znaky.

Příklady

Následující příklad zkontroluje IsRestricted vlastnost a zjistí, jestli je zakázáno nastavit nějaké hlavičky.

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

   // Get the associated response for the above request.
   HttpWebResponse^ myHttpWebResponse = dynamic_cast<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 restriced.
      if ( WebHeaderCollection::IsRestricted( dynamic_cast<String^>(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: {0}", e->Message );
   if ( e->Status == WebExceptionStatus::ProtocolError )
   {
      Console::WriteLine( "Status Code : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusCode );
      Console::WriteLine( "Status Description : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusDescription );
      Console::WriteLine( "Server : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->Server );
   }
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception is thrown. Message is : {0}", e->Message );
}
    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

Poznámky

Metoda IsRestricted vrátí informaci true , že hlavička je omezena a musí být nastavena pomocí vlastností místo přímo nebo je nastavena systémem. Záhlaví s omezeným přístupem jsou:

  • Přijmout

  • Připojení

  • Délka obsahu

  • Typ obsahu

  • Datum

  • Očekávat

  • Host

  • If-Modified-Since

  • Rozsah

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

Platí pro

IsRestricted(String, Boolean)

Zdroj:
WebHeaderCollection.cs
Zdroj:
WebHeaderCollection.cs
Zdroj:
WebHeaderCollection.cs

Testuje, jestli je možné pro požadavek nebo odpověď nastavit zadanou hlavičku HTTP.

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

Parametry

headerName
String

Hlavička, která se má testovat.

response
Boolean

true k otestování odpovědi; false a otestujte požadavek.

Návraty

truepokud je hlavička omezena; v opačném případě . false

Výjimky

headerName je null nebo Empty.

headerName obsahuje neplatné znaky.

Příklady

Následující příklad zkontroluje vlastnost a IsRestricted zjistí, jestli je zakázáno nastavit hlavičky požadavku.

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

   // Get the associated response for the above request.
   HttpWebResponse^ myHttpWebResponse = dynamic_cast<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 restriced.
      if ( WebHeaderCollection::IsRestricted( dynamic_cast<String^>(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: {0}", e->Message );
   if ( e->Status == WebExceptionStatus::ProtocolError )
   {
      Console::WriteLine( "Status Code : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusCode );
      Console::WriteLine( "Status Description : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->StatusDescription );
      Console::WriteLine( "Server : {0}", (dynamic_cast<HttpWebResponse^>(e->Response))->Server );
   }
}
catch ( Exception^ e ) 
{
   Console::WriteLine( "Exception is thrown. Message is : {0}", e->Message );
}
    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

Poznámky

Metoda IsRestricted se vrátí true k označení, že hlavička požadavku nebo odpovědi je omezená a musí být nastavena pomocí vlastností místo přímo nebo je nastavuje systém. Záhlaví s omezeným přístupem jsou:

  • Přijmout

  • Připojení

  • Délka obsahu

  • Typ obsahu

  • Datum

  • Očekávat

  • Host

  • If-Modified-Since

  • Rozsah

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

Platí pro