Monday, 18 February 2013

Check the View Source of a URL

Check the View Source of a URL

Use the following Code to get the viewsource of a particular URL Address:

Include these namespaces first:

using System.Net;
using System.IO;

Then Include two textboxes.. One for entering the URL and another for Showing the View Source.. Add a button to to make things Work:

    protected void btnSource_Click(object sender, EventArgs e)
            string URL=txtURL.Text;
            // Create a request for the URL.
            WebRequest request = WebRequest.Create(URL);
            // If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            // Display the status.
            Console.WriteLine (response.StatusDescription);
            // Get the stream containing content returned by the server.
            Stream ds= response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader rd= new StreamReader (ds);
            // Read the content. 
            string responser = rd.ReadToEnd ();

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top