Writing an Internet Client Application Using MFC WinInet Classes
The basis of every Internet client application is the Internet session. MFC implements Internet sessions as objects of class CInternetSession. Using this class, you can create one Internet session or several simultaneous sessions.
To communicate with a server, you need a CInternetConnection object as well as a CInternetSession
. You can create a CInternetConnection
by using CInternetSession::GetFtpConnection, CInternetSession::GetHttpConnection, or CInternetSession::GetGopherConnection. Each of these calls is specific to the protocol type. These calls do not open a file on the server for reading or writing. If you intend to read or write data, you must open the file as a separate step.
For most Internet sessions, the CInternetSession
object works hand-in-hand with a CInternetFile object:
For an Internet session, you must create an instance of CInternetSession.
If your Internet session reads or writes data, you must create an instance of
CInternetFile
(or its subclasses, CHttpFile or CGopherFile). The easiest way to read data is to call CInternetSession::OpenURL. This function parses a Universal Resource Locator (URL) supplied by you, opens a connection to the server specified by the URL, and returns a read-onlyCInternetFile
object.CInternetSession::OpenURL
is not specific to one protocol type — the same call works for any FTP, HTTP, or gopher URL.CInternetSession::OpenURL
even works with local files (returning aCStdioFile
instead of aCInternetFile
).If your Internet session does not read or write data, but performs other tasks, such as deleting a file in an FTP directory, you may not need to create an instance of
CInternetFile
.
There are two ways to create a CInternetFile
object:
If you use
CInternetSession::OpenURL
to establish your server connection, the call toOpenURL
returns aCStdioFile
.If use
CInternetSession::GetFtpConnection
,GetGopherConnection
, orGetHttpConnection
to establish your server connection, you must callCFtpConnection::OpenFile
,CGopherConnection::OpenFile
, orCHttpConnection::OpenRequest
, respectively, to return aCInternetFile
,CGopherFile
, orCHttpFile
, respectively.
The steps in implementing an Internet client application vary depending on whether you create a generic Internet client based on OpenURL
or a protocol-specific client using one of the GetConnection
functions.
What do you want to know more about
See also
Win32 Internet Extensions (WinInet)
MFC Classes for Creating Internet Client Applications
Prerequisites for Internet Client Classes