Tuesday, February 14, 2012

Fetch a web page from server using ASP.Net



Fetch a web page from web server
 

Step 1) Make sure internet connection of your machine is available

Step 2)Put the following code in your ASP.Net Page
            (It will take some time to exhicute the programe)

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;


public partial class socket : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            StreamReader inStream;
            WebRequest webRequest;
            WebResponse webresponse;
            webRequest = WebRequest.Create("http://www.yahoo.com");
            webresponse = webRequest.GetResponse();
            inStream = new StreamReader(webresponse.GetResponseStream());
            Response.Write(inStream.ReadToEnd());
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

    }
}

No comments:

Post a Comment