WebHeaderCollection.IsRestricted Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Test of de opgegeven HTTP-header kan worden ingesteld.
Overloads
| Name | Description |
|---|---|
| IsRestricted(String) |
Test of de opgegeven HTTP-header kan worden ingesteld voor de aanvraag. |
| IsRestricted(String, Boolean) |
Test of de opgegeven HTTP-header kan worden ingesteld voor de aanvraag of het antwoord. |
IsRestricted(String)
Test of de opgegeven HTTP-header kan worden ingesteld voor de aanvraag.
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
Parameters
- headerName
- String
De header die moet worden getest.
Retouren
true als de header is beperkt; anders false.
Uitzonderingen
headerName is null of Empty.
headerName bevat ongeldige tekens.
Voorbeelden
In het volgende voorbeeld wordt de IsRestricted eigenschap gecontroleerd om te zien of kopteksten niet mogen worden ingesteld.
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
Opmerkingen
De IsRestricted methode retourneert true om aan te geven dat een header is beperkt en moet worden ingesteld met behulp van eigenschappen in plaats van rechtstreeks of wordt ingesteld door het systeem. De beperkte headers zijn:
Accepteren
Connection
Lengte van inhoud
Inhoudstype
Date
Verwachten
Host
If-Modified-Since
Bereik
Verwijzende functie
Transfer-Encoding
User-Agent
Proxy-Connection
Van toepassing op
IsRestricted(String, Boolean)
Test of de opgegeven HTTP-header kan worden ingesteld voor de aanvraag of het antwoord.
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
Parameters
- headerName
- String
De header die moet worden getest.
- response
- Boolean
true om het antwoord te testen; false om de aanvraag te testen.
Retouren
true als de header is beperkt; anders, false.
Uitzonderingen
headerName is null of Empty.
headerName bevat ongeldige tekens.
Voorbeelden
In het volgende voorbeeld wordt de IsRestricted eigenschap gecontroleerd om te zien of eventuele aanvraagheaders niet mogen worden ingesteld.
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
Opmerkingen
De IsRestricted methode retourneert true om aan te geven dat een aanvraag- of antwoordheader is beperkt en moet worden ingesteld met behulp van eigenschappen in plaats van rechtstreeks of wordt ingesteld door het systeem. De beperkte headers zijn:
Accepteren
Connection
Lengte van inhoud
Inhoudstype
Date
Verwachten
Host
If-Modified-Since
Bereik
Verwijzende functie
Transfer-Encoding
User-Agent
Proxy-Connection