1.把文件下到本地
STDAPI URLDownloadToFileA(LPUNKNOWN,LPCSTR,LPCSTR,DWORD,LPBINDSTATUSCALLBACK);
STDAPI URLDownloadToFileW(LPUNKNOWN,LPCWSTR,LPCWSTR,DWORD,LPBINDSTATUSCALLBACK);
strIniURL= web
m_strIniTemp = m_strAppPath + _T("temp//update.ini");
if ( URLDownloadToFile( NULL, m_strIniURL, m_strIniTemp,0, NULL ) == S_OK )
{//直接下文件}
2.把文件全部读出
CString CVDialerDlg::URLDownloadA(CString pHttp,CString strObjName)
{
CString strRet = "Error";
CInternetSession m_cis;
CHttpConnection *m_pHttp;
DWORD m_dwHttpRequestFlags;
INTERNET_PORT m_dwPort=80;
m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
//
m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,3000);
m_pHttp=m_cis.GetHttpConnection(pHttp,m_dwPort);
//
//
CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObjName, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
try
{
pFile->SendRequest();
}
catch (...)
{
return strRet;
}
//
if(pFile)
{
char bufHttp[256]={0};
pFile->Read(bufHttp,256);
CString strMsg;
strMsg.Format("%s",bufHttp);
int nlen = strMsg.Find("UPDATEURL");
strMsg = strMsg.Left(nlen-2);//换行
nlen = strMsg.Find("VERSION=") +8;
nlen = strMsg.GetLength() - nlen;
strMsg= strMsg.Right(nlen);
strRet = strMsg ;
}
return strRet;
}
3.打开文件,逐行读出
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;
CString myData;
CString myUrl;
CString m_SiteInfo;
myUrl = " http://www.mmm.com/mmm/update/test1/update.ini";
myHttpFile=(CHttpFile*)mySession.OpenURL(myUrl);
while(myHttpFile->ReadString(myData))
{
m_SiteInfo = myData;
AfxMessageBox( m_SiteInfo );
}
myHttpFile->Close();
mySession.Close();