Use WinInet to develop Internet programs

Source: Internet
Author: User
Tags file url

 

  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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.