I have problem with web client connection. On most of the sites there is no problem to get title of page, but when I testing it found one site that raise error "The underlying connection was closed: An unexpected error occurred on a receive." concrete site is : "https://www.modbee.com/opinion/letters-to-the-editor/article111712867.html".
private string GetTitle(string link)
{
try
{
string html = webClient.DownloadString(link);
Regex reg = new Regex("<title>(.*)</title>");
MatchCollection m = reg.Matches(html);
if (m.Count > 0)
{
return m[0].Value.Replace("<title>", "").Replace("</title>", "");
}
else
return "";
}
catch (Exception e)
{
return labelError.Text = "You should insert correct URL\n";
}
}