次の方法で共有


Writing an Internet Client Application Using MFC WinInet Classes

OverviewHow Do I

The basis of every Internet client application is the Internet session. MFC implements Internet sessions as objects of class . Using this class, you can create one Internet session or several simultaneous sessions.

To communicate with a server, you need a object as well as a CInternetSession. You can create a CInternetConnection by using , , or . 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 object:

  • For an Internet session, you must create an instance of .

  • If your Internet session reads or writes data, you must create an instance of CInternetFile (or its subclasses, or ). The easiest way to read data is to call . 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 CInternetFile 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 a CStdioFile instead of a CInternetFile).

  • 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 to OpenURL returns a CInternetFile.   

  • If use CInternetSession::GetFtpConnection, GetGopherConnection, or GetHttpConnection to establish your server connection, you must call CFtpConnection::OpenFile, CGopherConnection::OpenFile, or CHttpConnection::OpenRequest, respectively, to return a CInternetFile, CGopherFile, or CHttpFile, 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 know more about?