Libcurl faq (


Many questions “how to translate CURL script to Clarion?” For example,

curl -X POST -H “Content-Type: application/json” -H “Authorization: Bearer Access-Token” -d “k1=v1&k2=v2”

-X POST means “POST” request and can be translated to curl.SetCustomRequest(‘POST’).
-H “…” means http header and can be translated to curl.AddHttpHeader(’…’).
To apply headers call curl.SetHttpHeaders().
-d “…” means post parameters which you pass to curl.SendRequest().

Sample code looks like this:

curl                            TCurlHttpClass
res                             CURLcode
url                             STRING(256), AUTO
PostParams                      STRING(4096), AUTO
respfile                        STRING(256), AUTO

  !-X POST
  !-H "Content-Type: application/json"
  curl.AddHttpHeader('Content-Type: application/json')

  !-H "Authorization: Bearer Access-Token"
  curl.AddHttpHeader('Authorization: Bearer Access-Token')

  !-- applies http headers added by AddHttpHeader calls
  url = ''
  PostParams = 'k1=v1&k2=v2'
  respfile = 'response.txt'
  res = curl.SendRequest(url, PostParams, respfile)
  IF res = CURLE_OK
    MESSAGE('Success, see file '& CLIP(respfile) &' for details', 'Post test', ICON:Asterisk)
  ELSIF res = -1
    MESSAGE('SendRequest failed: errcode '& res, 'Post test', ICON:Asterisk)
    MESSAGE('SendRequest failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)


Another example:

curl -u jsmith:jsmith -X POST -F “environment=TEM” -F “filename=Test” -F “[email protected]” ‘

-u jsmith:jsmith defines login and password and translated to curl.SetUserPwd(‘jsmith’, ‘jsmith’).
-F “environment=TEM” sends the data as a multipart formpost: curl.FormAdd(‘environment’, ‘TEM’).
-F “[email protected]” sends a file: curl.FormAddFile(‘multipartFile’, ‘mmabc.manifest’).
For formpost, call curl.FormPost() method instead of curl.SendRequest():


  !-- add form fields
  cfres = curl.FormAdd('environment', 'TEM')
  cfres = curl.FormAdd('filename', 'Test')
  !-- add file
  cfres = curl.FormAddFile('multipartFile', 'mmabc.manifest')

  curl.SetUserPwd('jsmith', 'jsmith')

  respfile = 'FormPost_response.txt'
  res = curl.FormPost('', respfile)


Send a file over http:

curl -H “Content-Type: application/json” --data-binary @test.json

Call curl.SendFile() with appropriate mime type (“application/json” in this case):


  url = ''
  infile = 'test.json'
  respfile = 'send_response.json'
  res = curl.SendFile(url, infile, 'application/json', respfile)