Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CGI socket.

Hello,

I need to write a VC++ application to check for the existence of a file
at a domain like http://mydomain.com/myfile.htm. The function just need to
return 1=it's there or 2=it's NOT there. Can anyone point me in the right
direction?

Thanks alot
Eric
0 Kudos
Message 1 of 2
(2,786 Views)
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
0 Kudos
Message 2 of 2
(2,786 Views)