Mega Code Archive

 
Categories / VB.Net / Network Remote
 

WebHeaderCollection IsRestricted tells whether the specified HTTP header can be set for the request

Imports System.IO Imports System.Net Imports System.Text public class MainClass     Public Shared Sub Main()       Try             Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)             Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)             Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebResponse.Headers           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  End Class