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-only
CInternetSession::OpenURLis not specific to one protocol type — the same call works for any FTP, HTTP, or gopher URL.
CInternetSession::OpenURLeven works with local files (returning a
CStdioFileinstead of a
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
There are two ways to create a
If you use
CInternetSession::OpenURLto establish your server connection, the call to
GetHttpConnectionto establish your server connection, you must call
CHttpConnection::OpenRequest, respectively, to return a
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