WebHeaderCollection.Remove 메서드

정의

컬렉션에서 지정된 헤더를 제거합니다.

오버로드

Name Description
Remove(HttpRequestHeader)

컬렉션에서 지정된 헤더를 제거합니다.

Remove(HttpResponseHeader)

컬렉션에서 지정된 헤더를 제거합니다.

Remove(String)

컬렉션에서 지정된 헤더를 제거합니다.

Remove(HttpRequestHeader)

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

컬렉션에서 지정된 헤더를 제거합니다.

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)

매개 변수

header
HttpRequestHeader

HttpRequestHeader 컬렉션에서 제거할 인스턴스입니다.

예외

WebHeaderCollection 인스턴스는 .의 HttpRequestHeader인스턴스를 허용하지 않습니다.

설명

Remove 는 컬렉션에서 지정된 헤더를 삭제합니다. 지정된 헤더가 없으면 메서드는 아무 것도 수행하지 않습니다.

적용 대상

Remove(HttpResponseHeader)

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

컬렉션에서 지정된 헤더를 제거합니다.

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)

매개 변수

header
HttpResponseHeader

HttpResponseHeader 컬렉션에서 제거할 인스턴스입니다.

예외

WebHeaderCollection 인스턴스는 .의 HttpResponseHeader인스턴스를 허용하지 않습니다.

설명

Remove 는 컬렉션에서 지정된 헤더를 삭제합니다. 지정된 헤더가 없으면 메서드는 아무 것도 수행하지 않습니다.

적용 대상

Remove(String)

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

컬렉션에서 지정된 헤더를 제거합니다.

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)

매개 변수

name
String

컬렉션에서 제거할 헤더의 이름입니다.

예외

name 입니다 nullEmpty.

name 는 제한된 헤더입니다.

-또는-

name 에 잘못된 문자가 포함되어 있습니다.

예제

다음 예제에서는 메서드를 Remove 사용하여 .에서 헤더를 제거합니다 WebHeaderCollection. 머리글을 제거한 후 이 예제에서는 기존 헤더를 모두 화면에 인쇄하여 제거되었음을 증명합니다.

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

설명

Remove 는 컬렉션에서 지정된 헤더를 삭제합니다. 지정된 헤더가 없으면 메서드가 반환됩니다.

적용 대상