您可以发出“
HEAD”请求而不是“
GET”请求?
(编辑)-大声笑!看来我以前做过!改为Wiki,以避免指责获得销售代表。因此,要测试URL而无需下载内容:
// using MyClient from linked postusing(var client = new MyClient()) { client.Headonly = true; // fine, no content downloaded string s1 = client.DownloadString("http://google.com"); // throws 404 string s2 = client.DownloadString("http://google.com/silly");}
您将
try/
catch在附近
DownloadString检查错误;没有错吗 存在…
使用C#2.0(VS2005):
private bool headOnly;public bool Headonly { get {return headOnly;} set {headonly = value;}}
和
using(WebClient client = new MyClient()){ // pre as before}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)