02-16-2011, 01:47 PM
Code:
Create a Very Simple Browser
#include <afxinet.h>
//assumes URL names have been initialized
CInternetSession session("My Session");
CStdioFile* pFile = NULL;
//use a URL and display a Web page
while (lpszURL = DisplayPage(...))
{
pFile = session.OpenURL(lpszURL);
while (pFile->Read(szBuff,1024) > 0)
{
//read file...
}
delete pFile;
}
session.Close();
Download a Web Page
//this code excerpt also demonstrates how to use //try/catch exception handling
#include <afxinet.h>
//assumes server, port and URL names have been initialized
CInternetSession session("My Session");
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString strServerName;
INTERNET_PORT nPort;
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)
{
//catch errors from WinInet
}
session.Close();
FTP a File
#include <afxinet.h>
//assumes server and file names have been initialized
CInternetSession session("My FTP Session");
CFtpConnection* pConn = NULL;
pConn = session.GetFtpConnection(lpszServerName);
//get the file
if (!pConn->GetFile(pstrRemoteFile, pstrLocalFile))
//display an error
delete pConn;
session.Close();
Retrieve a Gopher Directory
#include <afxinet.h>
//assumes file name has been initialized
CInternetSession session("My Gopher Session");
CGopherConnection* pConn = NULL;
CGopherFileFind* pFile;
pConn = session.GetGopherConnection("gopher.yoursite.com");
pFile = new CGopherFileFind(pConn);
BOOL bFound = pFile->FindFile(lpszFileToFind);
while (bFound)
{
bFound = pFile->FindNextFile();
//retrieve attributes of found file
}
delete pFile;
delete pConn;
session.Close();izin nyoret./..
![[Image: ibroke.png]](http://o2nri2.clan.su/onto/ibroke.png)
![[Image: sig2.png]](http://d.imagehost.org/0294/sig2.png)



