this artitle will descrip how to read header of any website and display its content
Require: write in C# and .Net
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Net;
using System.Web;
using System.IO;
namespace HTTPHeader
{
class Program
{
static void Main(string[] args)
{
GetHeader(“http://www.google.com”);
Console.ReadLine();
}
public static void GetHeader(string URL)
{
WebRequest request = WebRequest.Create(URL);
// If required by the server, set the credentials.
// request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Console.WriteLine(“############Begin Read Header”);
WebHeaderCollection wh = response.Headers;
foreach (string s in wh.AllKeys)
{
Console.WriteLine(s + “: ” + wh[s]);
}
// Display the status.
Console.WriteLine(response.StatusDescription);
Console.WriteLine(“############End Read Header”);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read all.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
}
}
}

Leave a Reply