The WinInet Development Kit provided by M $ is part of ActiveX technology. Later, MS packages WinInet APIs and provides corresponding MFC classes. The function of the WinNet development kit is to provide support for the http ftp Gopher protocol, so that developers can avoid writing code related to the underlying protocol when developing Internet programs. In addition, many features of WinInet are related to IE. For example, you can use IE to set and use data in IE cache. This section focuses on the use of HTTP.
CInternetSession in WinInet is a session management class. Generally, if you want to use the WinInet function, you need to create a session and then use the data access function based on the session. The CInternetSession constructor receives four parameters.CInternetSession (LPCTSTR pstrAgent = NULL, // Application name, which can be customized
DWORD dwContext = 1, // context tag. If the callback function is used, this value is sent to the callback function.
DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG ,//
LPCTSTR pstrProxyName = NULL, // address of the CERN proxy server, which is generally set to NULL
LPCTSTR pstrProxyBypass = NULL, // proxy server address
DWORD dwFlags = 0); // tag, usually set to 0
DwAccessType can be:
- INTERNET_OPEN_TYPE_PRECONFIG use connection settings in IE
- INTERNET_OPEN_TYPE_DIRECT connects directly to the server
- INTERNET_OPEN_TYPE_PROXY connection through Proxy Server
WhenSpecifies the proxy server address when dwAccessType is INTERNET_OPEN_TYPE_PROXY.
DwFlags can be:
- INTERNET_FLAG_DONT_CACHE does not store the obtained content in the cache.
- INTERNET_FLAG_OFFLINE offline
You can useCInternetSession: OpenURL opens a URL and reads data. The function prototype is:
CStdioFile * OpenURL (LPCTSTR pstrURL, // File URL
DWORD dwContext = 1, // context ID
DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII, // mark
LPCTSTR pstrHeaders = NULL, // data header sent to the server
DWORD dwHeadersLength = 0); // The length of the Data header sent to the server
DwFlags can be:
- INTERNET_FLAG_RELOAD force re-reading data
- INTERNET_FLAG_DONT_CACHE is not saved to the cache
- INTERNET_FLAG_TRANSFER_ASCII uses text data