直接上代码了。
1 /* 2 有效网址:http://tyq3.huaxiazi.com/mp3/全人类最冷的27个笑话/lxh025.wma 3 无效网址:http://tyq3.huaxiazi.com/mp3/100001/奇幻鬼故事/qhggs00802.mp3 4 */ 5 #include "Wininet.h" 6 #pragma comment (lib, "wininet.lib") 7 #define BUFFER_SIZE 20 8 BOOL CGetIPFromURLDlg::CheckUrlFileExist(TCHAR *ptcFileAddress) 9 { 10 HINTERNET hInternet = NULL; 11 TCHAR tcRet[BUFFER_SIZE + 1]; 12 DWORD dwBufLength = BUFFER_SIZE; 13 DWORD dwIndex = 0; 14 15 ZeroMemory(tcRet,sizeof(TCHAR) * (BUFFER_SIZE + 1)); 16 17 ghInstance = InternetOpen(L"InetURL:/1.0", 18 INTERNET_OPEN_TYPE_PRECONFIG, 19 NULL, 20 NULL, 21 0/*INTERNET_FLAG_ASYNC*/); 22 if(NULL == ghInstance) 23 { 24 RETAILMSG(1,(L"Call InternetOpen failed: %d ",GetLastError())); 25 return FALSE; 26 } 27 hInternet = InternetOpenUrl(ghInstance,ptcFileAddress,NULL,0,INTERNET_FLAG_RELOAD,0); 28 if(NULL == hInternet) 29 { 30 RETAILMSG(1,(L"Call InternetOpenUrl failed: %d ",GetLastError())); 31 return FALSE; 32 } 33 if(HttpQueryInfo(hInternet,HTTP_QUERY_STATUS_CODE,tcRet,&dwBufLength,&dwIndex)) 34 { 35 if(0 != _wcsicmp(tcRet,L"200") && 0 != _wcsicmp(tcRet,L"302")) 36 { 37 RETAILMSG(1,(L"Invalid www address: %s! ",tcRet)); 38 return FALSE; 39 } 40 } 41 else 42 { 43 RETAILMSG(1,(L"Call HttpQueryInfo failed: %d ",GetLastError())); 44 return FALSE; 45 } 46 47 RETAILMSG(1,(L"Valid www address: %s! ",tcRet)); 48 return TRUE; 49 }