Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 valid 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?

like image 866
Varun Mahajan Avatar asked Feb 02 '26 10:02

Varun Mahajan


1 Answers

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;
}
like image 142
Nick Dandoulakis Avatar answered Feb 04 '26 01:02

Nick Dandoulakis