Get Page Header using WebHeaderCollection

Lakhangarg
Posted by Lakhangarg under C# category on | Views : 4368
private void GetHeader()
{
Uri uri = new Uri(txtUrl.Text.Trim());
WebClient myClient = new WebClient();
// Open the page and get the response as a stream
Stream response = myClient.OpenRead("http://www.google.com");
WebHeaderCollection headers = myClient.ResponseHeaders;

Response.Write("Response headers:
");
for (int i = 0; i < headers.Count; i++)
{
Response.Write(headers.GetKey(i) + " : " + headers.Get(i) + "
");
}
StreamReader sr = new StreamReader(response);
// read the response into a string and show the result.
string s = sr.ReadToEnd();
Response.Write(s);
sr.Close();
response.Close();
}

Web Client class is used to get the client information and WebHeaderCollection to get the page header.

Comments or Responses

Login to post response