Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Those days I'm using libcurl with the bindings that are supplied with Lazarus/FPC... works perfectly fine (tested on Windows and Linux, I suppose MacOS will work too... on Windows you need to install the DLL, e.g. libcurl-x64.dll). No need to install anything on Lazarus/FPC. Below a basic (incomplete) example of a GET request with a custom header, but as this is just a binding to libcurl, it basically allows you to do anything, including other protocols (libcurl can even have SMTP support, depending how it is compiled).

  uses libcurl;

  function curl_callback(data: pointer; size: size_t; nmemb: size_t; str: PStream): size_t; cdecl;
  begin
    // do something with incoming data
  end;

  var http: pCurl;
      hdr: Pcurl_slist;
  begin
    http := curl_easy_init();
    // [...]
    hdr := curl_slist_append(NIL, pchar('Authorization: Bearer ' + EncodeStringBase64(AUTH_TOKEN)));
    curl_easy_setopt(http, CURLOPT_HTTPHEADER, [hdr]);
    curl_easy_setopt(http, CURLOPT_WRITEFUNCTION, [@curl_callback]);
    curl_easy_setopt(http, CURLOPT_URL, [pchar(API_URL)]);
    // [...]
    if (curl_easy_perform(http) <> CURLE_OK) then begin
      // [...]
    end;
  end.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: