惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

博客园 - GIS9 开发探索

实现在EXCEL软件中进行用户轨迹时空重合分析 疫情地图 | 制作10月12日沈阳浑南区核酸结果异常人员轨迹地图 表格排重 | EXCEL表格数据排重,使用相同颜色标记相同值 地理计算 | 批量创建图形的中点或质点 EXCEL教程 | 制作无症状感染者活动轨迹地图,以郑州疫情通告为例 EXCEL技能 | EXCEL中进行地图搜索并将结果显示在表格中 EXCEL技能 | EXCEL中实现地图快照,截大图、加水印、保存PNG、TIF、HTML文件 安装VS时,双击setup.exe后界面一闪而过的问题 【小o地图Excel插件版】计算两点间驾车路径,获取途径道路、驾车距离、耗时等信息 【小o地图Excel插件版】不止能做图表,还能抓58、大众点评网页数据... WIN10安装不上IIS,使用IISExpress作为发布服务 Excel地图插件(ExcelMaps) 局域网内通讯APP JDBC连接SqlServer错误:com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect - GIS9 开发探索 连接SQL Server数据库提示:Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection 错误 - GIS9 开发探索 AO开发时,ISqlWorkspace执行SQL语句,无法连接其他主机上的Oracle ArcGIS开发时,执行new SdeWorkspaceFactoryClass(); 出现COM类工厂的错误 [原创]WEB服务调试器,支持服务测试,监控告警 - GIS9 开发探索 web技术简介
【转】C#中判断网址是否有效
GIS9 开发探索 · 2018-09-26 · via 博客园 - GIS9 开发探索

本文内容来源网络,如涉及版权,请联系作者删除。

思路:C#语言判断网址是否正确,思路是向网址发起连接,根据状态判断网址是否有效。

代码如下:

//仅检测链接头,不会获取链接的结果。所以速度很快,超时的时间单位为毫秒
public static string GetWebStatusCode(string url,int timeout) {
HttpWebRequest req = null;
try
{
req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
req.Method = "HEAD"; //这是关键
req.Timeout = timeout;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
return Convert.ToInt32(res.StatusCode).ToString();
}
catch (Exception ex)
{
return ex.Message;
}
finally {
if (req != null)
{
req.Abort();
req = null;
}
}

}

//需要注意的是如果你使用多线程。。C#默认同时只有4个网络线程,如需要破解此限制需要添加代码
ServicePointManager.DefaultConnectionLimit = 100;

//此方法返回一个状态码。。状态码为200是为正常,异常时会返回错误信息。比如超时