赞
踩
1 包含头文件 #include <wininet.h>
2 导入库文件 #pragma comment(lib,"wininet.lib");
3 使用windowsAPI 实现获取网页源码
- /*获取网页的源码,参数1为网页链接,2为缓冲区指针*/
- bool CfasdfasdfDlg::GetHtml(LPCTSTR szURL ,CString& getbuf)
- {
- HINTERNET hInternet, hUrl;
- char buffer[1124];
- WCHAR wBuffer[1124];
-
- DWORD dwBytesRead = 0;
- DWORD dwBytesWritten = 0;
- BOOL bIsFirstPacket = true;
- BOOL bRet = true;
- int nNowcopyDate =0 ;
-
- hInternet = InternetOpen(_T("Mozilla/4.0 (compatible)"), INTERNET_OPEN_TYPE_PRECONFIG, NULL,INTERNET_INVALID_PORT_NUMBER,0);//初始化应用程序,使用WinNet
- if (hInternet == NULL)
- return FALSE;
-
- hUrl = InternetOpenUrl(hInternet, szURL, NULL, 0, INTERNET_FLAG_RELOAD, 0);//打开一个资源 ftp,gopher,http开头
-
- if (hUrl == NULL)
- {
-
- DWORD m = GetLastError();
- return FALSE;
- }
-
- do
- {
- memset(buffer,

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。