1. Download the MFC File
There are two methods:
A)
Create a cinternetsession object-> call cinternetsession: Openurl this function parses the URL, opens a connection with the server specified by the URL, and returns a read-only cinternetfile object-> cinternetfile :: read the file and analyze the cinternetsession
B)
Create a cinternetsession object-> call cinternetsession: gethttpconnection
Return chttpconnection object-> call chttpconnection: openrequest to create a chttpfile object-> chttpfile: sendrequest to send a connection request-> chttpfile: queryinfo to obtain HTTP information (such as file size and etag) | cinternetfile: Read File-> analysis structure cinternetsession
In the above process, if an error occurs, a cinternetexception exception is thrown.
In addition, you can make the following settings before opening the link.
Cinternetsession: setoption to read or set the internetquery option (for example, timeout or number of retries)
Cinternetsession: enablestatuscallback: sets the callback function to monitor the session status.
Chttpfile: addrequestheaders set the HTTP Request Header (called before chttpfile: sendrequest)
2. resumable upload
Resumable upload is actually implemented by setting the file range to be downloaded in the HTTP request header. A typical HTTP request header is
Gethttp: // class/download.microtool.de: 80/somedata.exe
HOST: download.microtool.de
Accept :*/*
Pragma: No-Cache
Cache-control: No-Cache
Referer: http: // class/download.microtool.de/
User-Agent: Mozilla/4.04 [En] (Win95; I; NAV)
Value Range: bytes = 554554-
Note that the last line: range: bytes = 554554-is in the format of range: bytes = start position-end position. In other words, you can set the start and end position of the HTTP request header, to obtain a part of the HTTP file.
3. Win32 wininet API implementation
Similar to the MFC function, the following functions are generally required for downloading:
Internetopen is the first function called. It returns an hinternet handle, which is defined as a hsession, that is, a session handle, which is equivalent to a cinternetsession.
Internetconnect uses the hsession handle. The returned HTTP connection handle is hconnect, which is equivalent to cinternetsession: gethttpconnection.
Httpopenrequest uses the hconnect handle. The returned handle is an HTTP request handle defined as hrequest, which is equivalent to chttpconnection: openrequest.
Httpsendrequest (equivalent to chttpfile: sendrequest), httpqueryinfo, internetsetfilepointer, and internetreadfile both use the handle returned by httpopenrequest, that is, hrequest.
Cinternetsession: Openurl implements three functions: internetconnect & httpopenrequest & httpsendrequest.
When these handles are no longer used, use the internetclosehandle function to close them to release the resources they occupy.
using wininet to develop Internet client application guide (I) http://www.vckbase.com/document/viewdoc? Id = 545
Use wininet to develop Internet client application guide (2) http://www.vckbase.com/document/viewdoc? Id = 546
using cinternetsession to encapsulate multithreading Http File Download http://www.vckbase.com/document/viewdoc? Id = 1693
resumable HTTP download http://sunyan331.spaces.live.com/blog/cns! 89b9f8bf2575e281! 947. entry
HTTP server breakpoint download files (which has a good source code) http://www.cnitblog.com/wangk/archive/2007/05/22/5942.html
write breakpoint resume and multi-thread download (with source code) http://www.bbbh.org/20060427/2620/
wininet: implementing resuming feature http://www.clevercomponents.com/articles/article015/resuming.asp
(a very detailed Code explanation) retrieving a file. HTTP http://www.codeproject.com/KB/IP/getwebfile.aspx