var url1 = "https://www.regulations.gov/contentStreamer?documentId=BIS-2018-0006-16235&attachmentNumber=2&contentType=pdf"; // url exist but issue when downloading
var url2 = "https://www.regulations.gov/contentStreamer?documentId=BIS-2018-0006-16010&attachmentNumber=2&contentType=pdf"; // url does not exist
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "HEAD";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
response.Close();
}
catch (WebException ex)
{
// i am getting http 500 server error exception when trying to see if both urls exist.
}
有人可以帮助我找到一种更好的方法来获取不存在的URL以及下载URL时出现问题的响应。