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

推荐订阅源

GbyAI
GbyAI
O
OpenAI News
Jina AI
Jina AI
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
WordPress大学
WordPress大学
F
Full Disclosure
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
F
Fortinet All Blogs
C
Check Point Blog
H
Hacker News: Front Page
H
Help Net Security
G
Google Developers Blog
The Cloudflare Blog
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
S
Secure Thoughts
U
Unit 42
L
LINUX DO - 最新话题
博客园 - 【当耐特】
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
TaoSecurity Blog
TaoSecurity Blog
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
AI
AI
aimingoo的专栏
aimingoo的专栏
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Heimdal Security Blog
Y
Y Combinator Blog
月光博客
月光博客
Hacker News: Ask HN
Hacker News: Ask HN
D
DataBreaches.Net
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Schneier on Security
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI

博客园 - gz.net

gridview绑定问题 - gz.net - 博客园 好久没来了。共享一个自动生成编号的存储过程 jsp数据库大全 login Microsoft Windows SharePoint Services ASP.NET程序中常用代码汇总(一) - gz.net - 博客园 ASP.NET动态生成HTML页面 日语的初次认识 日语的初次认识 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度? Eclipse快速上手指南 自己动手用c#写控件 代价 五种提高 SQL 性能的方法 js教程 HTML教程 HTML教程 存储过程编写经验三 存储过程经验二
检测远程URL是否存在的三种方法 ---转自孟子
gz.net · 2005-12-09 · via 博客园 - gz.net

Posted on 2005-12-09 11:12  gz.net  阅读(240)  评论()    收藏  举报

代码比较简单,这里不在多说。

private void Page_Load(object sender, System.EventArgs e) { string url1 = "http://dotnet.aspx.cc/"; string url2 = "http://dotnet.aspx.cc/Images/logo.gif"; Response.Write("<li>方法1:"); Response.Write(url1 + " 存在:" + UrlExistsUsingHttpWebRequest(url1).ToString()); Response.Write("<li>方法2:"); Response.Write(url1 + " 存在:" + UrlExistsUsingSockets(url1).ToString()); Response.Write("<li>方法3:"); Response.Write(url1 + " 存在:" + UrlExistsUsingXmlHttp(url1).ToString()); Response.Write("<li>方法1:"); Response.Write(url2 + " 存在:" + UrlExistsUsingHttpWebRequest(url2).ToString()); Response.Write("<li>方法3:"); Response.Write(url2 + " 存在:" + UrlExistsUsingXmlHttp(url2).ToString()); } private bool UrlExistsUsingHttpWebRequest(string url) { try { System.Net.HttpWebRequest myRequest =(System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); myRequest.Method = "HEAD"; myRequest.Timeout = 100; System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)myRequest.GetResponse(); return (res.StatusCode == System.Net.HttpStatusCode.OK); } catch(System.Net.WebException we) { System.Diagnostics.Trace.Write(we.Message); return false; } } private bool UrlExistsUsingXmlHttp(string url) { //注意:此方法需要引用Msxml2.dll MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass(); _xmlhttp.open("HEAD",url,false,null,null); _xmlhttp.send(""); return (_xmlhttp.status == 200 ); } private bool UrlExistsUsingSockets(string url) { if(url.StartsWith("http://")) url = url.Remove(0,"http://".Length); try { System.Net.IPHostEntry ipHost = System.Net.Dns.Resolve(url); return true; } catch (System.Net.Sockets.SocketException se) { System.Diagnostics.Trace.Write(se.Message); return false; } }