Share via


CInternetSession

Use class CInternetSession to create and initialize a single or several simultaneous Internet sessions and, if necessary, to describe your connection to a proxy server. If your Internet connection must be maintained for the duration of an application, you can create a CInternetSession member of the class CWinApp.

Once you have established an Internet session, you can call OpenURL. CInternetSession then parses the URL for you by calling the global function AfxParseURL. Regardless of its protocol type, CInternetSession interprets the URL and manages it for you. It can handle requests for local files identified with the URL resource "file://". OpenURL will return a pointer to a CStdioFile object if the name you pass it is a local file.

If you open a URL on an Internet server using OpenURL, you can read information from the site. If you want to perform service-specific (for example, HTTP, FTP, or gopher) actions on files located on a server, you must establish the appropriate connection with that server. To open a particular kind of connection directly to a particular service, use one of the following member functions:

QueryOption and SetOption allow you to set the query options of your session, such as time-out values, number of retries, and so on.

CInternetSession member functions SetCookie, GetCookie, and GetCookieLength provide the means to manage a Win32 cookie database, through which servers and scripts maintain state information about the client workstation.

During an Internet session, a transaction such as a search or data download can take appreciable time. The user might want to continue working, or might want to have status information about the progress of the transaction. To handle this problem, CInternetSession provides for searches and data transfer to occur asychronously, allowing the user to perform other tasks while waiting for the transfer to complete. If you want to provide the user with status information, or if you want to handle any operations asynchronously, three conditions must be set:

  • In the constructor, dwFlags must include INTERNET_FLAG_ASYNC.

  • In the constructor, dwContext must be set to a nonzero value.

  • You must establish a call back function by calling EnableStatusCallback

Use the overridable member function OnStatusCallback to get status information on asynchronous retrieval. To use this overridable member function, you must derive your own class from CInternetSession.

For more information about asynchronous operations, see the article in Visual C++ Programmer’s Guide. For general information about using the MFC WinInet classes, see the article in Visual C++ Programmer’s Guide.

Note   CInternetSession will throw an AfxThrowNotSupportedException for unsupported service types. Only the following service types are currently supported: FTP, HTTP, gopher, and file.

#include <afxinet.h>

Class MembersBase ClassHierarchy Chart

Samples   

See Also   CInternetConnection, CHttpConnection, CFtpConnection, CGopherConnection