Here's a function that I think will do what you want:
#include "windows.h"
#include "wininet.h"
#pragma comment(lib, "wininet.lib")
bool WebLinkExists(LPCTSTR url)
{
bool linkExists = false;
HINTERNET hInternet = ::InternetOpen(_T("LinkChecker"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet != NULL)
{
HINTERNET hRequest = ::InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_RELOAD, NULL);
if (hRequest != NULL)
{
DWORD buffer = 0, bufferLength = sizeof(DWORD);
::HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &buffer, &bufferLength, NULL);
linkExists = (buffer == HTTP_STATUS_OK);
::InternetCloseHandle(hRequest);
}
::InternetCloseHandle(hInternet);
}
return linkExists;
}
- Elton