WebHeaderCollection.Remove removes the specified header from the collection. : WebHeaderCollection « Network Remote « VB.Net






WebHeaderCollection.Remove removes the specified header from the collection.

 

Imports System.IO
Imports System.Net
Imports System.Text

public class MainClass
   Shared Sub Main()
        Try
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
            Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers
            myWebHeaderCollection.Set("Cache-Control", "no-cache")
            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
            myWebHeaderCollection.Remove("Cache-Control")
            myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
            myHttpWebResponse.Close()
        Catch e As ArgumentException
            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 
End Class

   
  








Related examples in the same category

1.WebHeaderCollection.Add inserts the specified header into the collection.
2.WebHeaderCollection.GetValues gets an array of header values stored in a header.
3.WebHeaderCollection.IsRestricted tells whether the specified HTTP header can be set for the request.
4.WebHeaderCollection.Set sets the specified header to the specified value.