HttpGet(LPCTSTR lpszFullUrl, char *pBuffer, int iBufferSize)
{
if (lpszFullUrl == NULL)
return false;
HINTERNET hNet = ::InternetOpen(_TEXT("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"),PRE_CONFIG_INTERNET_ACCESS,NULL,INTERNET_INVALID_PORT_NUMBER,0);
//HINTERNET hNet = InternetOpen(_TEXT(""),PRE_CONFIG_INTERNET_ACCESS,NULL,NULL,0);
if(hNet == NULL)
{
return false;
}
HINTERNET hUrlFile = InternetOpenUrl(hNet,lpszFullUrl,NULL,0,INTERNET_FLAG_RELOAD,0);
if(!hUrlFile)
{
return false;
}
memset(pBuffer, 0, iBufferSize);
DWORD dwBytesRead = 0;
char szTemp[3074] = { 0 };
DWORD dwTotalReadBytes = 0;
while(InternetReadFile(hUrlFile, szTemp, sizeof(szTemp) - 1, &dwBytesRead))
{
if (0 == dwBytesRead)
break;
szTemp[dwBytesRead] = 0;
// 缓冲区大小不够时,停止向目的缓冲区复制数据,跳出
if (dwTotalReadBytes + dwBytesRead >= (UINT)iBufferSize)
{
pBuffer[iBufferSize - 1] = 0;
break;
}
strcat_s(pBuffer, 3074, szTemp);
ZeroMemory(szTemp, sizeof(szTemp));
dwTotalReadBytes += dwBytesRead;
}
InternetCloseHandle(hUrlFile);
InternetCloseHandle(hNet);
return true;
}
{
if (lpszFullUrl == NULL)
return false;
HINTERNET hNet = ::InternetOpen(_TEXT("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"),PRE_CONFIG_INTERNET_ACCESS,NULL,INTERNET_INVALID_PORT_NUMBER,0);
//HINTERNET hNet = InternetOpen(_TEXT(""),PRE_CONFIG_INTERNET_ACCESS,NULL,NULL,0);
if(hNet == NULL)
{
return false;
}
HINTERNET hUrlFile = InternetOpenUrl(hNet,lpszFullUrl,NULL,0,INTERNET_FLAG_RELOAD,0);
if(!hUrlFile)
{
return false;
}
memset(pBuffer, 0, iBufferSize);
DWORD dwBytesRead = 0;
char szTemp[3074] = { 0 };
DWORD dwTotalReadBytes = 0;
while(InternetReadFile(hUrlFile, szTemp, sizeof(szTemp) - 1, &dwBytesRead))
{
if (0 == dwBytesRead)
break;
szTemp[dwBytesRead] = 0;
// 缓冲区大小不够时,停止向目的缓冲区复制数据,跳出
if (dwTotalReadBytes + dwBytesRead >= (UINT)iBufferSize)
{
pBuffer[iBufferSize - 1] = 0;
break;
}
strcat_s(pBuffer, 3074, szTemp);
ZeroMemory(szTemp, sizeof(szTemp));
dwTotalReadBytes += dwBytesRead;
}
InternetCloseHandle(hUrlFile);
InternetCloseHandle(hNet);
return true;
}