I need to read status (403 or 404) of HTTP-header when read a URL by using C# in ASP.Net. For example: URL1: https://www.instagram.com/khaniki.ah URL2: https://www.instagram.com/khaniki.ah123456 I get status 200 (HttpStatusCode.Found) when I try to read URL1 and same for reading URL2 while it's not exist; See more in photos.
Also, I use this following code:
var Url = UrlTbx.Text;
Uri urlCheck = new Uri(Url);
HttpWebRequest HttpRequest = (HttpWebRequest)WebRequest.Create(Url);
HttpRequest.Timeout = 15000;
HttpRequest.AllowAutoRedirect = false;
HttpRequest.ServicePoint.Expect100Continue = false;
HttpRequest.ContentType = "application/x-www-form-urlencoded";
//HttpRequest.Method = "GET";
HttpRequest.Method = "HEAD";//both methods was tested
HttpWebResponse HttpResponse;
try
{
HttpResponse = (HttpWebResponse)HttpRequest.GetResponse();
if (HttpResponse.StatusCode == HttpStatusCode.Found)
Lit.Text = "YES" + " / " + HttpResponse.StatusCode;
else if (HttpResponse.StatusCode == HttpStatusCode.NotFound)
Lit.Text = "NO" + " / " + HttpResponse.StatusCode;
}
catch (Exception)
{
return false;
}

