验证文件存在于网站上
我正在尝试创建一个简单的函数来验证网站上是否存在特定文件。
Web 请求设置为 head,以便我可以获取文件长度而不是下载整个文件,但我收到“无法连接到远程服务器”异常。 如何验证网站上是否存在文件?
WebRequest w;
WebResponse r;
w = WebRequest.Create("http://website.com/stuff/images/9-18-2011-3-42-16-PM.gif");
w.Method = "HEAD";
r = w.GetResponse();
编辑:我的错,在我检查日志后发现我的防火墙阻止了http请求。 它没有提示我输入例外规则,所以我认为这是一个错误。
I am attempting to make a simple function that verifies that a specific file exists on a website.
The web request is set to head so I can get the file length instead of downloading the entire file, but I get "Unable to connect to the remote server" exception.
How can I verify a file exists on a website?
WebRequest w;
WebResponse r;
w = WebRequest.Create("http://website.com/stuff/images/9-18-2011-3-42-16-PM.gif");
w.Method = "HEAD";
r = w.GetResponse();
edit: My bad, turns out my firewall was blocking http requests after I checked the log.
It didnt prompt me for an exception rule so I assumed it was a bug.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经测试过这个,它工作正常:
尝试使用以下网址: http://www .centrosardegna.com/images/losa/losaabbasanta.png 然后修改图片名称,会返回 false。 ;-)
I've tested this and it works fine:
try it with this url: http://www.centrosardegna.com/images/losa/losaabbasanta.png then modify the image name and it will return false. ;-)