다음을 통해 공유


MFC WinInet 클래스를 사용하여 인터넷 클라이언트 응용 프로그램 작성

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 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 CStdioFile.

  • 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.

추가 정보

참고 항목

개념

Win32 인터넷 확장(WinInet)

인터넷 클라이언트 응용 프로그램을 만들기 위한 MFC 클래스

인터넷 클라이언트 클래스의 필수 구성 요소