WebHeaderCollection.IsRestricted WebHeaderCollection.IsRestricted WebHeaderCollection.IsRestricted WebHeaderCollection.IsRestricted Method

定義

指定した HTTP ヘッダーを設定できるかどうかをテストします。Tests whether the specified HTTP header can be set.

オーバーロード

IsRestricted(String) IsRestricted(String) IsRestricted(String) IsRestricted(String)

指定した HTTP ヘッダーを要求に対して設定できるかどうかをテストします。Tests whether the specified HTTP header can be set for the request.

IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean)

指定した HTTP ヘッダーを要求または応答に対して設定できるかどうかをテストします。Tests whether the specified HTTP header can be set for the request or the response.

IsRestricted(String) IsRestricted(String) IsRestricted(String) IsRestricted(String)

指定した HTTP ヘッダーを要求に対して設定できるかどうかをテストします。Tests whether the specified HTTP header can be set for the request.

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 String String String

テストするヘッダー。The header to test.

戻り値

ヘッダーが制限付きの場合は true。それ以外の場合は falsetrue if the header is restricted; otherwise false.

例外

headerNamenull または Empty です。headerName is null or Empty.

headerName に無効な文字が含まれています。headerName contains invalid characters.

次の例ではIsRestricted 、プロパティをチェックして、禁止されているヘッダーがあるかどうかを確認します。The following example checks the IsRestricted property to see if any headers are prohibited from being set.

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ヘッダーが制限されており、直接ではなくプロパティを使用して設定する必要があることを示すためにを返します。The IsRestricted method returns true to indicate that a header is restricted and must be set using properties instead of directly or is set by the system. 制限されたヘッダーは次のとおりです。The restricted headers are:

  • AcceptAccept

  • ConnectionConnection

  • ContentLengthContent-Length

  • Content-TypeContent-Type

  • DateDate

  • ExpectExpect

  • HostHost

  • If-Modified-SinceIf-Modified-Since

  • 範囲Range

  • RefererReferer

  • 転送-エンコードTransfer-Encoding

  • ユーザーエージェントUser-Agent

  • プロキシ接続Proxy-Connection

IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean)

指定した HTTP ヘッダーを要求または応答に対して設定できるかどうかをテストします。Tests whether the specified HTTP header can be set for the request or the response.

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 String String String

テストするヘッダー。The header to test.

response
Boolean Boolean Boolean Boolean

フレームワークが応答または要求をテストするかどうかを指定します。Does the Framework test the response or the request?

戻り値

ヘッダーが制限付きの場合は true。それ以外の場合は falsetrue if the header is restricted; otherwise, false.

例外

headerNamenull または Empty です。headerName is null or Empty.

headerName に無効な文字が含まれています。headerName contains invalid characters.

次の例ではIsRestricted 、プロパティをチェックして、要求ヘッダーの設定が禁止されているかどうかを確認します。The following example checks the IsRestricted property to see if any request headers are prohibited from being set.

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要求または応答ヘッダーが制限されていることを示すためにを返し、直接ではなく、またはシステムによって設定されたプロパティを使用して設定する必要があります。The IsRestricted method returns true to indicate that a request or response header is restricted and must be set using properties instead of directly or is set by the system. 制限されたヘッダーは次のとおりです。The restricted headers are:

  • AcceptAccept

  • ConnectionConnection

  • ContentLengthContent-Length

  • Content-TypeContent-Type

  • DateDate

  • ExpectExpect

  • HostHost

  • If-Modified-SinceIf-Modified-Since

  • 範囲Range

  • RefererReferer

  • 転送-エンコードTransfer-Encoding

  • ユーザーエージェントUser-Agent

  • プロキシ接続Proxy-Connection

適用対象