다음을 통해 공유


WebHeaderCollection.IsRestricted 메서드

정의

지정된 HTTP 헤더를 설정할 수 있는지 여부를 테스트합니다.

오버로드

IsRestricted(String)

지정된 HTTP 헤더를 요청에 설정할 수 있는지 여부를 테스트합니다.

IsRestricted(String, Boolean)

지정된 HTTP 헤더를 요청 또는 응답에 설정할 수 있는지 여부를 테스트합니다.

IsRestricted(String)

Source:
WebHeaderCollection.cs
Source:
WebHeaderCollection.cs
Source:
WebHeaderCollection.cs

지정된 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

매개 변수

headerName
String

테스트할 헤더입니다.

반환

헤더가 제한되어 있으면 true이고, 그렇지 않으면 false입니다.

예외

headerNamenull 또는 Empty입니다.

headerName에 잘못된 문자가 들어 있는 경우

예제

다음 예에서는 속성을 확인 IsRestricted 하여 헤더 설정이 금지되어 있는지 확인합니다.

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

설명

메서드는 IsRestricted 헤더가 제한되고 직접 또는 시스템에 의해 설정되는 대신 속성을 사용하여 설정되어야 함을 나타내기 위해 를 반환 true 합니다. 제한된 헤더는 다음과 같습니다.

  • 동의함

  • 연결

  • Content-Length

  • 콘텐츠 형식

  • 날짜

  • Expect

  • 호스트

  • If-Modified-Since

  • 범위

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

적용 대상

IsRestricted(String, Boolean)

Source:
WebHeaderCollection.cs
Source:
WebHeaderCollection.cs
Source:
WebHeaderCollection.cs

지정된 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

매개 변수

headerName
String

테스트할 헤더입니다.

response
Boolean

true 응답을 테스트하려면 이고, false 요청을 테스트합니다.

반환

헤더가 제한되어 있으면 true이고, 그렇지 않으면 false입니다.

예외

headerNamenull 또는 Empty입니다.

headerName에 잘못된 문자가 들어 있는 경우

예제

다음 예에서는 속성을 확인 IsRestricted 하여 요청 헤더 설정이 금지되어 있는지 확인합니다.

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

설명

메서드는 IsRestricted 요청 또는 응답 헤더가 제한되고 직접 또는 시스템에서 설정되는 대신 속성을 사용하여 설정되어야 함을 나타내기 위해 를 반환 true 합니다. 제한된 헤더는 다음과 같습니다.

  • 동의함

  • 연결

  • Content-Length

  • 콘텐츠 형식

  • 날짜

  • Expect

  • 호스트

  • If-Modified-Since

  • 범위

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

적용 대상