Get response from website using webclient
We can get the response from the website using the
class WebClient. The following code will explain it clearly
The following code is the initial stage of working with the web access
WebClient MyWebClient = new WebClient();
MyWebClient.BaseAddress = "http://www.Dotnetspider.com";
MyWebClient.DownloadFile("http://www.Dotnetspider.com", "index.htm");
StreamReader MyStreamReader =new StreamReader(MyWebClient.OpenRead("index.htm"));
Console.WriteLine(MyStreamReader.ReadToEnd());
Console.WriteLine (MyWebClient.Headers.Count);
WebHeaderCollection Myheader = MyWebClient.ResponseHeaders;
Console.WriteLine(Myheader.Count);
for (int i = 0; i < Myheader.Count; i++)
Console.WriteLine(Myheader.GetKey(i) + " : " + header[i]);
MyStreamReader.Close();
Code Explanation
1. Create the instance of the Webclient.
2. Create the stream by getting the response from the website using webclient.
3. Read the stream using stramreader and use it.
4. We can collect the headers using the WebHeaderCollection.
5. using for loop we can get all the headers.
By
Nathan