http TacHTTP component
Hierarchy Properties Methods Events
Return to Introduction  Previous page  Next page
The acHTTP component is extremely easy to use WinInet-based HTTP client component which allows to post and get any data from the Web via HTTP protocol. With acHTTP you can grab Web pages, download files and documents (or only their headers without the content), get results of the CGI programs (for example, results of web-based search engines / databases), or even upload files to the Web-based programs.  
The acHTTP can grab web contents both in binary and text formats, supports cache of Internet Explorer, can pause and resume broken downloads, read data from password protected directories and automatically supports several proxy authentication schemes (basic, digest, NTLM etc).  

key Key features
·works with both, HTTP and HTTPS protocols + can read files from local area network using "file://" prefix for URLs;  
·can either POST or GET data to remote CGI programs;  
·can upload files by HTTP protocol, using multipart/form-data POST method, introduced in RFC 1867;  
·can download or upload data to password protected Web directories;  
·flexible cache control, provided by WinINet library. The acHTTP just use standard cache of Internet Explorer to retreive or write downloaded files to cache and save bandwidth from re-downloading. The cache control can be is easily customized by various options;  
·can pause and resume broken downloads;  
·automatically accepts SSL certificates, can allow or disallow access to sites with invalid or expired certificates;  
·can automatically retreive proxy information from Internet Options of Control Panel, make HTTP requests with custom proxy settins or directly without any proxy server;  
·automatically supports several secure proxy authentication schemes: basic, digest, NTLM (NT Lan Manager), MSN (Microsoft Network), DPA (Distributed Password Authentication) and RPA (Remote Passphrase Authentication by CompuServe)  
·using super stable threading mechanism, which allows to execute HTTP requests from both, standard, and ActiveX forms.  

How to use ?
Just specify the location of Internet document which you would like to receive to URL property, and call Read method to start downloading. Use OnDone event to handle received data, or use OnHTTPError, OnConnLost and OnHostUnreachable events to handle errors. To show the download progress, write OnProgress event handler.  
If you need to send some data to the CGI program via POST method, specify the request in the POSTData property before Reading. Usually acHTTP component can automatically recognize which request method you would like to use, POST or GET, however if you wish you can specify it in the RequestMethod property.  
If you want to just check the HTTP headers of remote document without downloading it (or before downloading) — write the OnHeaderInfo event handler to receive all the headers (document size, content type, language, encoding, last modification and expiration date and so forth). You can also use this event to check the file information and decide whether you really want to download it…  
To read files from password protected Web directories you should specify login information in Username and Password properties. Also use OnPasswordRequest event to specify login information dynamically.  
iiinfo acHTTP can upload files via HTTP protocol, using multipart/form-data POST method, introduced in RFC 1867. Uploading still easy to use as well as downloading. For more details see Upload method and OnUploadFieldRequest, OnUploadProgress events.  
iiinfo acHTTP automatically recognize and supports several Proxy authentication schemes (basic, digest, NTLM (NT Lan Manager), MSN (Microsoft Network), DPA (Distributed Password Authentication) and RPA (Remote Passphrase Authentication by CompuServe)). If user works through secure proxy server which requires user authentication — specify ProxyUsername and ProxyPassword properties to the Proxy structure, or write OnProxyAuthenticationRequest event handler to prompt users for the username and password required to access the Web via proxy server.  
If you need to terminate downloading process imediately — call Abort method. In case if you downloading some binary data to file (specified in OutputFileName property), you can resume the downloading at any time using Resume method.  
iiinfo The acHTTP automatically uses simple but smart scheme of checking whether the file which you're trying to Resume has been updated or modified. Before downloading of the data which should be appended, it downloads small data chunk (with size specified in TransferBufferSize property), before the break, and compares with the same data chunk at the end of file.  
In case if compared data are equal — it continue downloading and append downloaded data to the end of local file. Otherwise it assume that file which beging downloaded has been changed, and starts download from beginning.  
By default TransferBufferSize = 4Kb, so every time when you call Resume method, the component download 4Kb of extra "rollback" data to check file consistancy.  

tip Also, the acHTTP unit provides another, extremally simpe way to receive some text information from the Web, using HTTPReadString function, without any acHTTP component on the form and without specifying its properties and handling the events. The HTTPReadString can be used to download some text string or HTML document from specified location.  

Usage example
In Delphi:  
In C++ Builder:  
Compiled executable:  

Important note!
iiwarning C++ Builder programmers: Don't forget to add "INET.LIB" file (or "WININET.LIB" in C++ Builder 6 and higher, this file can be found in "..\CBuilderX\Lib" directory) to your project which uses the acHTTP. The INET.LIB contains the prototypes for required Internet routines from WinInet.DLL.  

See also
acHTTPDownloadQueue, acThread, acAutoUpgrader, acSendMail and acWebImage components.