如何检测远程路径上的一个.exe文件是否存在

dinglannames 2012-05-03 11:23:33
http://pcs2.78v.com/仙剑奇侠传3.exe 例如检测这个文件是否存在 
...全文
155 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2012-05-03
  • 打赏
  • 举报
回复
浏览器访问
http://pcs2.78v.com/仙剑奇侠传3.exe

404 Not Found
nginx
dinglannames 2012-05-03
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

这个能检测rar文件,但是检测.exe文件永远都返回 404?
是你的服务器配置的问题,浏览器访问得到的是什么
[/Quote]
浏览器访问直接下载
孟子E章 2012-05-03
  • 打赏
  • 举报
回复
这个能检测rar文件,但是检测.exe文件永远都返回 404?
是你的服务器配置的问题,浏览器访问得到的是什么
Ki1381 2012-05-03
  • 打赏
  • 举报
回复
直接用浏览器下载也返回404吗?

这个跟对方Web Server配置有关系的,不是所有后缀的文件都可以被发布出来。
dinglannames 2012-05-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

private bool UrlIsExist(String url)
{
System.Uri u = null;
try
{
u = new Uri(url);
}
catch { return false; }
bool isExist = false;
System.Net.HttpWebRequest r = System.Net.……
[/Quote]这个能检测rar文件,但是检测.exe文件永远都返回 404
孟子E章 2012-05-03
  • 打赏
  • 举报
回复
private bool UrlIsExist(String url)
{
System.Uri u = null;
try
{
u = new Uri(url);
}
catch { return false; }
bool isExist = false;
System.Net.HttpWebRequest r = System.Net.HttpWebRequest.Create(u) as System.Net.HttpWebRequest;
r.Method = "HEAD";
try
{
System.Net.HttpWebResponse s = r.GetResponse() as System.Net.HttpWebResponse;
if (s.StatusCode == System.Net.HttpStatusCode.OK)
{
isExist = true;
}
}
catch (System.Net.WebException x)
{
try
{
isExist = ((x.Response as System.Net.HttpWebResponse).StatusCode != System.Net.HttpStatusCode.NotFound);
}
catch { isExist = (x.Status == System.Net.WebExceptionStatus.Success); }
}
return isExist;
}

判断网络地址 Url 是否存在的方法
http://dotnet.aspx.cc/file/Delect-Url-Exists.aspx
bdmh 2012-05-03
  • 打赏
  • 举报
回复
webclient去down一下,然后捕获错误,看看是否404
dinglannames 2012-05-03
  • 打赏
  • 举报
回复
还有请问一下电驴的下载地址能检测到是否有效吗?
ksr12333 2012-05-03
  • 打赏
  • 举报
回复
那说明服务器没有配置exe的mime类型............

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧