Skip to content

Instantly share code, notes, and snippets.

@dkounal
Created July 11, 2023 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkounal/b8ab592c74d668ccbd1b3c7536a31623 to your computer and use it in GitHub Desktop.
Save dkounal/b8ab592c74d668ccbd1b3c7536a31623 to your computer and use it in GitHub Desktop.
if not CurlIsAvailable then exit('no curl available');
res:=crFailedInit;
hnd:=curl.easy_init;
if hnd <> Nil then
begin
curl.easy_setopt(hnd, coSSLVerifyPeer, 0);
curl.easy_setopt(hnd, coSSLVerifyHost, 0);
curl.easy_setopt(hnd, coURL, Pointer(url));
curl.easy_setopt(hnd, coUserName, Pointer(uname));
curl.easy_setopt(hnd, coPassword, Pointer(passw));
headers:=nil;
headers := curl.slist_append(headers, Pointer(FormatUtf8('accept: %', ['application/xml'])));
headers := curl.slist_append(headers, Pointer(FormatUtf8('api-key: %', [applkey])));
curl.easy_setopt(hnd, coHttpHeader, headers);
curl.easy_setopt(hnd, coCustomRequest, RawUtf8('GET'));
curl.easy_setopt(hnd, coWriteData, @responseData);
curl.easy_setopt(hnd, coWriteFunction, @CurlWriteRawByteString);
res := curl.easy_perform(hnd);
if res = crOk then result:=responseData
else
begin
result:=Format('Curl told us %d (%s)', [Ord(res), curl.easy_strerror(res)]);
responseData := '';
end;
curl.slist_free_all(headers);
curl.easy_cleanup(hnd);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment