The following code excerpts how to create a simple browser, download a web page, operate a file with FTP and find a gopher file. They are not a complete example, which does not contain an abnormality, just a summary of the recent writer.
1 Create a very simple browser #include
2 Download a web page #include
pServer = session.GetHttpConnection (strServerName, nPort); pFile = pServer-> OpenRequest (CHttpConnection :: HTTP_VERB_GET, strObject); pFile-> AddRequestHeaders (szHeaders); pFile-> SendRequest (); pFile-> QueryInfoStatusCode (dwRet);
IF (dwret == http_status_ok) {uint nread = pfile-> read (SZBUFF, 1023); while (NREAD> 0) {// read file}} delete pfile; delete pserver;} catch (cinternetException * pEX) {/ / Capture Wininet's Error} session.close ();
3 Operate a file with FTP #include
PCONN = session.GetftpConnect (LPSZSERVERNAME); // Get file IF (! pConn-> getfile (pstrremotefile, pstrlocalfile) // Display an error Delete PCONN; session.close ();
4 Receive a gopher directory #include
pConn = session.GetGopherConnection ( "gopher.yousite.com"); pFile = new CGopherFileFind (pConn); BOOL bFound = pFile-> FindFile (lpszFileToFind); while (bFound) {bFound = pFile-> FindNextFile (); // Re-found file attribute} delete pfile; delete pconn; session.close (); When using the Wininet class library, users can use the member function onstatusCallback of the application's CinternetSession object to get status information. If the user inherits its own CinternetSession object, written a callback overstatuscallback and allowing the status, the MFC will use the progress information of all the activities of the International Interconnection Network as a parameter, call the user's onstatusCallback function.