WebHeaderCollection.Remove Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Odebere zadanou hlavičku z kolekce.
Přetížení
Remove(HttpRequestHeader) |
Odebere zadanou hlavičku z kolekce. |
Remove(HttpResponseHeader) |
Odebere zadanou hlavičku z kolekce. |
Remove(String) |
Odebere zadanou hlavičku z kolekce. |
Remove(HttpRequestHeader)
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
Odebere zadanou hlavičku z kolekce.
public:
void Remove(System::Net::HttpRequestHeader header);
public void Remove (System.Net.HttpRequestHeader header);
override this.Remove : System.Net.HttpRequestHeader -> unit
Public Sub Remove (header As HttpRequestHeader)
Parametry
- header
- HttpRequestHeader
Instance HttpRequestHeader , která se má z kolekce odebrat.
Výjimky
Tato WebHeaderCollection instance nepovoluje instance .HttpRequestHeader
Poznámky
Remove odstraní zadanou hlavičku z kolekce. Pokud zadaná hlavička neexistuje, metoda neprovede nic.
Platí pro
Remove(HttpResponseHeader)
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
Odebere zadanou hlavičku z kolekce.
public:
void Remove(System::Net::HttpResponseHeader header);
public void Remove (System.Net.HttpResponseHeader header);
override this.Remove : System.Net.HttpResponseHeader -> unit
Public Sub Remove (header As HttpResponseHeader)
Parametry
- header
- HttpResponseHeader
Instance HttpResponseHeader , která se má z kolekce odebrat.
Výjimky
Tato WebHeaderCollection instance nepovoluje instance .HttpResponseHeader
Poznámky
Remove odstraní zadanou hlavičku z kolekce. Pokud zadaná hlavička neexistuje, metoda neprovede nic.
Platí pro
Remove(String)
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
- Zdroj:
- WebHeaderCollection.cs
Odebere zadanou hlavičku z kolekce.
public:
void Remove(System::String ^ name);
public:
override void Remove(System::String ^ name);
public void Remove (string name);
public override void Remove (string name);
member this.Remove : string -> unit
override this.Remove : string -> unit
Public Sub Remove (name As String)
Public Overrides Sub Remove (name As String)
Parametry
- name
- String
Název hlavičky, která se má z kolekce odebrat.
Výjimky
name
je null
Empty.
Příklady
Následující příklad používá metodu Remove k odebrání hlavičky z objektu WebHeaderCollection. Po odebrání záhlaví se v tomto příkladu na obrazovku vytiskne všechna existující záhlaví, aby se prokázalo, že bylo odebráno.
try
{
// Create a web request for S"www.msn.com".
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://www.msn.com" ));
// Get the headers associated with the request.
WebHeaderCollection^ myWebHeaderCollection = myHttpWebRequest->Headers;
// Set the Cache-Control header.
myWebHeaderCollection->Set( "Cache-Control", "no-cache" );
// Get the associated response for the above request.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
// Print the headers of the request to console.
Console::WriteLine( "Print request headers after adding Cache-Control for first request:" );
printHeaders( myHttpWebRequest->Headers );
// Remove the Cache-Control header for the new request.
myWebHeaderCollection->Remove( "Cache-Control" );
// Get the response for the new request.
myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
// Print the headers of the new request with->Item[Out] the* Cache-Control header.
Console::WriteLine( "Print request headers after removing Cache-Control for the new request:" );
printHeaders( myHttpWebRequest->Headers );
myHttpWebResponse->Close();
}
// Catch exception if trying to remove a restricted header.
catch ( ArgumentException^ e )
{
Console::WriteLine( "Error : Trying to remove a restricted header" );
Console::WriteLine( "ArgumentException is thrown. Message is : {0}", e->Message );
}
catch ( WebException^ e )
{
Console::WriteLine( "WebException is thrown. Message 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 headers associated with the request.
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
// Set the Cache-Control header.
myWebHeaderCollection.Set("Cache-Control", "no-cache");
// Get the associated response for the above request.
HttpWebResponse myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
// Print the headers of the request to console.
Console.WriteLine("Print request headers after adding Cache-Control for first request:");
printHeaders(myHttpWebRequest.Headers);
// Remove the Cache-Control header for the new request.
myWebHeaderCollection.Remove("Cache-Control");
// Get the response for the new request.
myHttpWebResponse = (HttpWebResponse) myHttpWebRequest.GetResponse();
// Print the headers of the new request without the Cache-Control header.
Console.WriteLine("Print request headers after removing Cache-Control for the new request:");
printHeaders(myHttpWebRequest.Headers);
myHttpWebResponse.Close();
}
// Catch exception if trying to remove a restricted header.
catch(ArgumentException e) {
Console.WriteLine("Error : Trying to remove a restricted header");
Console.WriteLine("ArgumentException is thrown. Message is :" + e.Message);
}
catch(WebException e) {
Console.WriteLine("WebException is thrown. Message 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 headers associated with the request.
Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers
'Set the Cache-Control header.
myWebHeaderCollection.Set("Cache-Control", "no-cache")
'Get the associated response for the above request.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'Print the headers of the request to console.
Console.WriteLine("Print request headers after adding Cache-Control for first request")
printHeaders(myHttpWebRequest.Headers)
'Remove the Cache-Control header for the new request.
myWebHeaderCollection.Remove("Cache-Control")
'Code example for "Remove" method of "WebHeaderCollection" ends here.
'Get the response for the new request.
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'Print the headers of the new request without the Cache-Control header.
Console.WriteLine("Print request headers after removing Cache-Control for the new request")
printHeaders(myHttpWebRequest.Headers)
myHttpWebResponse.Close()
'Catch exception if trying to remove a restricted header.
Catch e As ArgumentException
Console.WriteLine("Error : Trying to remove a restricted header")
Console.WriteLine(e.Message)
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
Remove odstraní zadanou hlavičku z kolekce. Pokud zadaná hlavička neexistuje, vrátí se metoda.