I found this code from here it works for uri like "https://google.com" but it doesn't work for something like "https://172.61.58.168/Account/Login/". I actually don't know why. I have an App using that URI that has an API that I need to call. I can successfully do an api-call and I just decided to make a validation first if the base uri exist and is valid.
Help. Thanks.
code:
bool isHttpValid = false;
try
{
//Creating the HttpWebRequest
HttpWebRequest request = WebRequest.Create("https://172.16.85.186/Account/Login/") as HttpWebRequest;
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
//Getting the Web Response.
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//Returns TRUE if the Status code == 200
response.Close();
isHttpValid = true;
}
catch
{
//Any exception will returns false.
isHttpValid = false;
}