开发者

How to check if a link exists or not in VC++?

开发者 https://www.devze.com 2022-12-15 23:02 出处:网络
I have a link. I have checked that the link is a valid URL through regular expressions. Now, I want to check if the link is a v开发者_StackOverflow社区alid http link or not. i.e. it should not be a no

I have a link. I have checked that the link is a valid URL through regular expressions. Now, I want to check if the link is a v开发者_StackOverflow社区alid http link or not. i.e. it should not be a non-existing link. Is there a way in VC++ 6.0 (MFC) to check that?


One option is to try to get data from that URL by using the URLOpenBlockingStream function.

Example:

#include <Urlmon.h>

IStream* pStream = NULL;
if (SUCCEEDED(URLOpenBlockingStream(0, "URL string", &pStream, 0, 0))) {
    // Release the stream immediately since we don't use the data.
    pStream->Release();
    return TRUE;
}
else {
    return FALSE;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号