Two issues:
1. if you enter
www.gmail.com
in the text box, you have to check the URL format in programmatic way and add the (
http://
) portion so that, the input URL actually become http://www.gmail.com before calling
WebRequest.Create(url);
2. I have tested the code with setting the url to
"http://www.gmail.com"
and it works quite fine (Doesn't throw any exception). You please try to debug your code and check whether there is any other code that throws exception. Also, you need to make sure that your machine has Internet connection enable so that your code actually is able to hit a web request.
also, you should modify the
try..catch
portion so that, you can view the exact exception detail as follows:
try
{
..
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}