//Step1:初始化
int CMyGetWebData::InitWebSession(CString szServerName, int iPort)
{
//create a new internet session
m_pInnetSession = new CMyInterSession();
//enable call back function, so can handle some message
//m_pInnetSession->EnableStatusCallback();
//init m_pInnetSession, tell it my instance
//m_pInnetSession->Init(this);
try
{
//then open to a server,and return a http connection
m_pHttpConnection = m_pInnetSession->GetHttpConnection((LPCTSTR)szServerName, INTERNET_FLAG_RELOAD, (INTERNET_PORT)iPort);
if(m_pHttpConnection == NULL)
{
//have some error
return -1;
}
}
catch(CInternetException *pExcp)
{
//have some exception, handle it, then delete, waiwai
pExcp->Delete();
return -1;
}
return 0;
}
//Step2:发送请求,我当时写的是用GET方法。可以携带任何Request头。
/****
采用GET方式获得一个网页数据
szGetStr: The Get URL string(not include 'get')
****/
int CMyGetWebData::SendGetRequest(CString szGetStr)
{
try
{
m_pHttpFile = m_pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, (LPCTSTR)szGetStr, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD);