post the code of CString CWebWorld::GetWebPage(const CString& Url);
解决方案 »
- 文件系统\注册表解析 --DLL
- IMediaSeek::GetCurrentPosition导致程序挂起
- 继续问GetOpenFileName的问题
- 怎样获得执行文件所在的路径??
- 各位有用WINDOWS开发基于对话框框架应用程序的教程吗(不用MFC)
- 如何在连接库中调用主程序里的回调函数
- 救命。。关于插入记录的问题。!!
- 用SAPI怎么动态改变语音识别时的语言种类?
- 请问用什么方法将(BYTE*)的变量变成CString变量?望高手指教!!
- $$$$$$《深入浅出MFC》中对于动态创建对象的解释$$$$$$
- 我枚举了所有窗口的句柄,并对他们发送::postmessage(hwnd,wm_close,0,0),然后奇怪的事情发生了...
- 文档关闭问题
char szSizeBuffer[32];
DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer);
DWORD dwFileSize;
DWORD dwBytesRead;
BOOL bSuccessful;
CString Contents; // Setting default error message
Contents = m_ErrorMessage;
// Opening the Url and getting a Handle for HTTP file
hHttpFile = InternetOpenUrl(m_Session, (const char *) Url, NULL, 0, 0, 0); if (hHttpFile)
{
// Getting the size of HTTP Files
BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL) ; if(bQuery==TRUE)
{
// Allocating the memory space for HTTP file contents
dwFileSize=atol(szSizeBuffer);
LPSTR szContents = Contents.GetBuffer(dwFileSize); // Read the HTTP file
BOOL bRead = ::InternetReadFile(hHttpFile, szContents, dwFileSize, &dwBytesRead);
if (bRead)
bSuccessful = TRUE; ::InternetCloseHandle(hHttpFile); // Close the connection.
} }
else
{
// Connection failed.
bSuccessful = FALSE;
}
return Contents;
char szSizeBuffer[32];
DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer);
DWORD dwFileSize;
DWORD dwBytesRead;
BOOL bSuccessful;
CString Contents; // Setting default error message
Contents = m_ErrorMessage;
// Opening the Url and getting a Handle for HTTP file
hHttpFile = InternetOpenUrl(m_Session, (const char *) Url, NULL, 0, 0, 0); if (hHttpFile)
{
// Getting the size of HTTP Files
BOOL bQuery = ::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH, szSizeBuffer, &dwLengthSizeBuffer, NULL) ; if(bQuery==TRUE)
{
// Allocating the memory space for HTTP file contents
dwFileSize=atol(szSizeBuffer);
LPSTR szContents = Contents.GetBuffer(dwFileSize); // Read the HTTP file
BOOL bRead = ::InternetReadFile(hHttpFile, szContents, dwFileSize, &dwBytesRead);
if (bRead)
bSuccessful = TRUE; ::InternetCloseHandle(hHttpFile); // Close the connection.
} }
else
{
// Connection failed.
bSuccessful = FALSE;
}
return Contents;
bool SaveUrl(LPCTSTR url, LPCTSTR filename)
{
HINTERNET hNet = ::InternetOpen("Outlook",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hUrlFile = ::InternetOpenUrl(hNet,
url,
NULL,
0,
INTERNET_FLAG_RELOAD,
0) ;
char buffer[10*1024] ;
DWORD dwBytesRead = 1;
BOOL bRead=TRUE;
CFile file;
file.Open(filename,CFile::modeCreate|CFile::modeWrite);
while(bRead&&dwBytesRead>0)
{
bRead = ::InternetReadFile(hUrlFile,
buffer,
sizeof(buffer),
&dwBytesRead);
if(dwBytesRead>0)
file.Write(buffer,dwBytesRead);
}
::InternetCloseHandle(hUrlFile) ;
::InternetCloseHandle(hNet) ;
file.Close();
AfxMessageBox("finished");
return bRead;
}
void CC02021101Dlg::OnOK()
{
// TODO: Add extra validation here
bool bret=SaveUrl("http://club.pchome.net/bbs2.php?topic=40&lanmuid=2","C:\\temp\\test.html");
if(bret)
AfxMessageBox("true");
else
AfxMessageBox("false");
}
Not all html page return correct file length, they may return -1! So sometimes you will fail. It is not related with php. The url "http://www.csdn.net/expert/Topic/465/465220.shtm" also return -1as I remembered.
yes,u got it!