protected void Page_Load(object sender, EventArgs e) { string URL = "http://wwww.yahoo.com"; //Create a Webclient instance. WebClient mywebclient = new WebClient(); //Download page data. Response.Write("Downloading " + URL); //Download the web resource and save it into a data buffer. byte[] mydatabuffer = mywebclient.DownloadData(URL); //Display the downloaded data. string download = Encoding.ASCII.GetString(mydatabuffer); Response.Write(download); } }
1 answers
protected void Page_Load(object sender, EventArgs e)
{
string URL = "http://www.yahoo.com";
//Create a request for the URL.
WebRequest request=WebRequest.Create(URL);
request.Proxy=null;
//Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Display the status.
Response.Write(response.StatusDescription);
if (response.StatusDescription=="OK")
{
Response.Write("\n Site Exists.");
}
else
{
Response.Write("Does Not Exists.");
}
}
answered 9 months ago by:
0
protected void Page_Load(object sender, EventArgs e)
{
string URL = "http://wwww.yahoo.com";
//Create a Webclient instance.
WebClient mywebclient = new WebClient();
//Download page data.
Response.Write("Downloading " + URL);
//Download the web resource and save it into a data buffer.
byte[] mydatabuffer = mywebclient.DownloadData(URL);
//Display the downloaded data.
string download = Encoding.ASCII.GetString(mydatabuffer);
Response.Write(download);
}
}
answered 9 months ago by:
0
protected void Page_Load(object sender, EventArgs e)
{
string URL =@"http://www.yahoo.com";
//Create a request for the URL.
WebRequest request = WebRequest.Create(URL);
request.Proxy = null;
try
{
//Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Display the status.
Response.Write(response.StatusDescription);
Response.Write("\n Site Exists.");
}
catch (Exception exc)
{
Response.Write("\n Site does not exists.");
}
}
answered 9 months ago by:
0
all depends of the return status code.
If the response status is 500, it means that the page is dead, it has an internal Server Error.
answered 9 months ago by:
0
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!