您的位置:首页 > 编程语言 > C#

C#判断连接是否可下载

2016-03-17 17:31 405 查看
private static bool IsCanConnect(string url)
{
HttpWebRequest req = null;
HttpWebResponse res = null;
bool CanCn = true;   //设成可以连接;
try
{
req = (HttpWebRequest)WebRequest.Create(url);
res = (HttpWebResponse)req.GetResponse();
}
catch (Exception)
{
CanCn = false;   //无法连接
}
finally
{
if (res != null)
{
res.Close();
}
}
return CanCn;
}


原文章地址:http://www.cnblogs.com/xiaopin/archive/2012/02/22/2363519.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: