cURL is useful for when the http.pas and hostname.pas units from the Powtils don't offer what you need. cURL can be used for example to grab SSL/HTTPS pages which at current time of writing the http.pas unit cannot do.
cURL also offers access to FTP and FTPS which is again something the http.pas unit cannot do. cURL is very well known and installed on almost all systems and servers.
Our friend Jeff (YetAnotherGeek) maintains the CurlPas wrapper that makes cURL easy to access through Pascal programs. (Thanks Jeff!)
program cURLtest; {$mode objfpc} {$H+} uses pwumain, // web functions {$IFDEF UNIX}libc,{$ENDIF} curl_h; // Jeff's (yetanothergeek) Curl C API wrapper var hCurl: pCurl; function writer(p: pchar; sz: size_t; nmemb: size_t; stream: pointer): size_t; cdecl; var s: string; len: longword; tmpp: pchar; begin len:= sz * nmemb; if len <> 0 then begin getmem(tmpp, len + 1); // allocate memory for TEMPORARY buffer move(p^, tmpp^, len); // copies data sent to us into a TEMPORARY buffer tmpp<len>:= #0; // note: actually square brackets, lufdoc needs to be updated // DEAL WITH DATA HERE, INSTEAD OF WEBWRITE YOU COULD USE A STRING OR BUFFER webwrite('<p>------------------ BEGIN DATA CHUNK -------------------------<p>'); webwrite(string(tmpp)); webwrite('<p>------------------- END DATA CHUNK --------------------------<p>'); freemem(tmpp); end; result:= len; end; //var // p: pointer; begin hCurl:= curl_easy_init; if ( hCurl <> nil ) then begin curl_easy_setopt(hCurl, CURLOPT_VERBOSE, true); curl_easy_setopt(hCurl, CURLOPT_URL, 'curl.haxx.se'); curl_easy_setopt(hCurl, CURLOPT_FOLLOWLOCATION ,true); //curl_easy_setopt(hCurl,CURLOPT_WRITEDATA, p); curl_easy_setopt(hCurl, CURLOPT_WRITEFUNCTION, @writer); curl_easy_perform(hCurl); curl_easy_cleanup(hCurl); end; end.The above example uses the simple libcURL C API however you can use Jeff's curl objects or other curl wrappers (there are a few out there).
The writer() function above is what deals with the data.. you could store the data in a string and then parse it based on your needs, or do whatever with it. In the above simple example I simply write the data to web browser output as soon as each chunk is received.
Also, the default cURL naming convention is kind of ugly and verbose (i.e. size_t and curl_easy_setopt ) - you could wrap that into a nicer naming scheme or you can use existing Curl objects from Jeff which have a nicer naming scheme. At some point the Powerful Web Utils package may contain a simple Curl wrapper unit with a nice naming convention that matches the Powerful Web Utils naming convention (CurlGet, CurlSetOpt, etc).