I am trying to use WebClient
to download a file from web using a WinForms application. However, I really only want to download HTML file. Any other type I will
Here is a method using TCP, which http is built on top of. It will return when connected or after the timeout (milliseconds), so the value may need to be changed depending on your situation
var result = false;
try {
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) {
var asyncResult = socket.BeginConnect(yourUri.AbsoluteUri, 80, null, null);
result = asyncResult.AsyncWaitHandle.WaitOne(100, true);
socket.Close();
}
}
catch { }
return result;