System.Net.WebException: The remote name could not be resolved: 'http'
at System.Net.HttpWebRequest.GetResponse()
at Helpers.CheckUrl(String url)
我的代码:
try
{
if (IsURLValid(url))
{
Uri requestUri = new Uri(url);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);
httpWebRequest.Timeout = 30000;
httpWebRequest.Method = "HEAD";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0";
httpWebRequest.Accept = "*/*";
httpWebRequest.ServicePoint.Expect100Continue = false;
httpWebRequest.AllowAutoRedirect = false;
httpWebRequest.MaximumAutomaticRedirections = 4;
CookieContainer cookies = new CookieContainer();
httpWebRequest.CookieContainer = cookies;
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
MessageBox.Show(httpWebResponse.StatusCode.ToString());
if(httpWebResponse.StatusCode == HttpStatusCode.OK)
{
return true;
}
}
return false;
}
catch (WebException e)
{
CommonCodes.WriteLog(e.ToString());
return false;
}
- 似乎仅在URL为http时才发生异常。有任何想法吗?我想实现url是否有效。我在另一台具有不同DNS的PC上尝试过此问题。 HttpWebResponse行正在生成此异常。验证网址是否有效的最佳方法是什么?
http://1cosmetology.ru/gogyjod/wl62l4f.php?ybmqpftpd=vb-net-grid-control