I am checking if a url exist, using HttpWebRequest.
The problem, it's not working for some url's.
Example:
http://www.gkrs.no/
https://www.politi.no/kripos/statistikk/narkotika/
These url's exist. But show up in the code as not existing.
It is working for most of the url's i am checking, its just these two that are causing some issues. Does anyone have any examples of what i still need to check for. Maybe there is something different in their headers.
I have tried both GET and HEAD request methods.
I am still new to programming and might need a simpler explanation. Sorry for bad English, not my first language.
Any help would be appreciated.
internal static bool IsValidLenke(string url){
if (String.IsNullOrEmpty(url))
return false;
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "HEAD";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
response.Close();
return (response.StatusCode == HttpStatusCode.OK);
}
catch
{
//Any exception will returns false.
return false;
}
}