调用data = OpenSocket("localhost", CHttpConnection::HTTP_VERB_POST, "message.php");
是放在onTimer中的,如果放在按扭单击中就会变,为什么呢?如何让他在定时中会变呢?CString CpftoolsDlg::OpenSocket(CString hostname, UINT type, CString url, CString data, DWORD port)
{
CInternetSession m_InetSession(_T("session"));
CHttpConnection *pServer = NULL;
CHttpFile *pFile = NULL;
CString m_strHtml = NULL;
try
{
pServer = m_InetSession.GetHttpConnection(hostname, port);
pFile = pServer->OpenRequest(type, url);
CString szHeaders ="Content-Type: application/x-www-form-urlencoded";
pFile->SendRequest(szHeaders, (LPVOID)(LPCTSTR)data, data.GetLength());
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
//m_Mutex.Lock();
if (dwRet == HTTP_STATUS_OK)
{
CString m_strRead;
while (pFile->ReadString(m_strRead))
{
m_strHtml += m_strRead;
}
}
pFile->Close();
//m_Mutex.Unlock();
delete pFile;
pServer->Close();
delete pServer;
}
catch (CInternetException *e)
{
CString s;
s.Format("Internet Exception\r\nm_dwError%u, m_dwContextError%u", e->m_dwError, e->m_dwContext);
AfxMessageBox(s);
}
return m_strHtml;
}