预览加载中,请您耐心等待几秒...
1/4
2/4
3/4
4/4

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

在应用程序中下载WEB页 为了在应用程序中下载WEB页,我们设计了WebWorld类。WebWorld类是一个高级 连接,它使用了WinInet,可以使你的应用程序完成HTTP,FTP或Gopherclient协议, 使用它你可以非常方便的下载WEB页。 这个类提供了两个重要函数 CStringGetWebPage(constCString&Url); voidSetErrorMessage(CStrings); 源代码: /* /---------------------------------------------------------------------------------------------- //WebWorld.h:interfacefortheCWebWorldclass. /---------------------------------------------------------------------------------------------- */ #include"wininet.h" classCWebWorld { public: voidSetErrorMessage(CStrings); CStringGetWebPage(constCString&Url); CWebWorld(); virtual~CWebWorld(); private: CStringm_ErrorMessage; HINTERNETm_Session; }; /* /------------------------------------------------------------------------------------------------ //WebWorld.cpp:implementationoftheCWebWorldclass. /------------------------------------------------------------------------------------------------ */ #include"stdafx.h" #include"WebThief.h" #ifdef_DEBUG #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #definenewDEBUG_NEW #endif #defineAGENT_NAME"CodeguruBrowser1.0" ////////////////////////////////////////////////////////////////////// //Construction/Destruction ////////////////////////////////////////////////////////////////////// CWebWorld::CWebWorld() { DWORDdwError; //InitializetheWin32Internetfunctions m_Session=::InternetOpen(AGENT_NAME, INTERNET_OPEN_TYPE_PRECONFIG,//Useregistrysettings. NULL,//Proxyname.NULLindicatesusedefault. NULL,//Listoflocalservers.NULLindicatesdefault. 0); dwError=GetLastError(); } CWebWorld::~CWebWorld() { //Closingthesession ::InternetCloseHandle(m_Session); } CStringCWebWorld::GetWebPage(constCString&Url) { HINTERNEThHttpFile; charszSizeBuffer[32]; DWORDdwLengthSizeBuffer=sizeof(szSizeBuffer); DWORDdwFileSize; DWORDdwBytesRead; BOOLbSuccessful; CStringContents; //Settingdefaulterrormessage Contents=m_ErrorMessage; //OpeningtheUrlandgettingaHandleforHTTPfile hHttpFile=InternetOpenUrl(m_Session,(constchar*)Url,NULL,0,0