如何检查文件是否在其网址的web服务器的存在? [英] How to check if a file exists on an webserver by its URL?
问题描述
在我们的应用中有某种联机帮助。它的工作原理很简单:如果用户点击帮助按钮的URL是构建依赖于当前的语言和帮助上下文(如http://example.com/help/+ [LANG_ID] +[HELP_CONTEXT])和。所谓的浏览器中的
in our application we have some kind of online help. It works really simple: If the user clicks on the help button a URL is build depending on the current language and help context (e.g. "http://example.com/help/" + [LANG_ID] + "[HELP_CONTEXT]) and called within the browser.
所以我的问题是:我如何检查文件是否在Web服务器上存在而不加载完整的文件内容
So my question is: How can i check if a file exists on the web server without loading the complete file content?
感谢您的帮助
更新!。感谢您的帮助我的问题已经回答了
现在我们有代理认证问题的一个不能发送HTTP请求;)
推荐答案
您可以使用.NET做。HEAD请求,然后看一下响应的状态
You can use .NET to do a HEAD request and then look at the status of the response.
您的代码将是这个样子(改编自的弱旅HTTP HEAD请求):
Your code would look something like this (adapted from The Lowly HTTP HEAD Request):
// create the request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
// instruct the server to return headers only
request.Method = "HEAD";
// make the connection
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// get the status code
HttpStatusCode status = response.StatusCode;
下面是详细介绍了的 的状态代码可以通过枚举的StatusCode返回。
Here's a list detailing the status codes that can be returned by the StatusCode enumerator.
这篇关于如何检查文件是否在其网址的web服务器的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!