原文地址:
http://abujj.me/archives/697
最近要判断一些地址,比如http://…..zip 是否存在.然后做一些操作
方法很多.
1. 下载看状态码 200(需要下载)
2.不用下载.请求head.是否成功(不需要下载)
这是.肯定要用第二个方法,.
HttpWebResponse response = null; var request = (HttpWebRequest)WebRequest.Create(/* url */); request.Method = "HEAD"; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { /* A WebException will be thrown if the status of the response is not `200 OK` */ } finally { // Don't forget to close your response. if (response != null) { response.Close() } }