如何检查给定的URL是否存在 [英] How to check if given url is existed

查看:109
本文介绍了如何检查给定的URL是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我必须检查给定的URL是否存在.

因此,我尝试使用InternetCheckConnection()函数.
但是程序挂在那一行.

可能是什么原因?
还是您还有其他建议来检查url是否存在?

Hi, everyone.
I have to check if given url is exist.

So I tried to use InternetCheckConnection() function.
But the program is hanging on that line.

What can be reason?
or do you have any other suggestion to check url is exist?

推荐答案

没有诸如验证URL是否存在之类的东西.您只能验证其有效性,即是否符合网址格式.之后,没有验证.

如果服务器无法识别某个URL,则通常会产生404错误,这可能是也可能不是其有效性的识别,因为某些URL可能会简单地过期,而某些则可能由于服务器问题而无法提供服务目前,有些人可能根本不喜欢您的语言环境或IP地址等.

呼叫InternetCheckConnection不会在这里帮助您,它主要是按照它说的做,检查您的Internet连接,但这不是您要查询的内容.尽管它确实验证是否可以打开URL,但它是呼叫的辅助对象,并且可能例如在URL格式验证上失败.但是,即使成功,也不会因为上述原因而表明该URL有效.

您需要将搜索范围缩小到更有意义的范围.

示例:

There is no such thing as verifying URL for existence. You can only verify it for validity, i.e. compliance with the URL format. After that there is no verification.

If a server does not recognize a certain URL, it will typically generate a 404 error, which may or may not be the recognition of its validity, because some URL-s can simply expire, some may fail to be served because of a server problem at the moment, some may simply not like your locale or your IP address, etc...

Calling InternetCheckConnection isn''t gonna help you much here, it mainly does what it says, checks your internet connection, but this isn''t what you inquired about. Although it does verify whether it can open the URL, it is secondary for the call, and may fail, for instance, on URL format validation. But even if it succeeded, it would be no indication of the URL being valid for reasons already described above.

You need to narrow your search to something more meaningful.

Examples:


  1. 如果要验证URL引用了现有文件,请尝试打开并读取该文件.
  2. 如果要分析服务器对URL的响应,只需阅读并解析响应.
  3. 如果要使用某种格式的自定义URL,请在本地进行检查.


等等.而且,如果您发布了一个定义更好的新问题,我将很乐意为您解答;)


and so on. And if you publish a new, better defined question, I''d be happy to answer that one ;)


看看 WsOpenChannel [ cURL和libcurl [
Have a look at HttpClientExample[^].

Pay attention to the use of WsOpenChannel[^], this where the application establishes a connection based on an url.

If you need to support older versions of Windows, try cURL and libcurl[^].

Best regards
Espen Harlinn


我在PHP函数get_headers()中知道用于检查URL的地址,可能对您有所帮助.
I knew in PHP function get_headers() for check URL, may be this can help.


这篇关于如何检查给定的URL是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆