I wanted a small bit of code to grab the headers from a website, but it's breaking on me mercilessly. Here it is:
public String GetWebHeaders(string url)
{
StringBuilder sb = new StringBuilder();
try
{
//Connects to the url
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
webRequest.Method = WebRequestMethods.Http.Get;
webRequest.Credentials = new NetworkCredential("username", "password");
//Loops through all the headers
for (int i = 0; i < webRequest.GetResponse().Headers.Count; i++)
{
//Adds all the headers to the stringbuilder.
sb.AppendLine(webRequest.GetResponse().Headers[i].ToString());
}
}
catch (WebException webEx)
{
...
Go to the complete details ...