Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Start a new CURL easy session.

Component Version macOS Windows Linux Server iOS SDK
CURL 2.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "CURL.New" )




A new CURL handle.


Start a new CURL easy session.
This function must be the first function to call, and it returns a CURL handle that you must use as input to other CURL functions. CURL.New initializes curl and this call MUST have a corresponding call to CURL.Release when the operation is complete. You can use one curl object for multiple transfers reusing same connection.
Result is a number greater than zero on success. Errors returned may be about low memory or two many CURL connections.
CURL reference numbers are starting at 16000 and counting up for each new session.


Initialize a CURL session and set URL:

$curl = MBS( "CURL.New" )
$r = MBS("CURL.SetOptionURL"; $curl; $URL)

Query a REST API:

# new session
Set Variable [$curl; MBS( "CURL.New" ) ] ]
# set URL for this REST API
Set Variable [$rMBS("CURL.SetOptionURL"; $curl; "https://example.test/wc-api/v2/products") ]
# make a post with some data
Set Variable [$rMBS("CURL.SetOptionPost"; $curl; 1) ]
Set Variable [$rMBS("CURL.SetOptionPostFields"; $curl; "{product:{...}}"; "UTF-8") ]
# set credentials
Set Variable [$rMBS("CURL.SetOptionUserName"; $curl; "consumer_key") ]
Set Variable [$rMBS("CURL.SetOptionPassword"; $curl; "consumer_secret") ]
# add header option
Set Variable [$rMBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/json", "Expect:" ) ]
# disable security for this demo:
Set Variable [$rMBS( "CURL.SetOptionSSLVerifyHost"; $curl; 0 ) ]
Set Variable [$rMBS( "CURL.SetOptionSSLVerifyPeer"; $curl; 0 ) ]
# with log messages
Set Variable [$rMBS( "CURL.SetOptionVerbose"; $curl; 1 ) ]
# run it!
Set Variable [$ErrorMBS( "CURL.Perform"; $curl ) ]
# check debug messages
Set Variable [$MessagesMBS("CURL.GetDebugMessages"; $curl) ]
# check result
Set Variable [$OutputMBS("CURL.GetResultAsText"; $curl) ]
# and cleanup
Set Variable [$rMBS( "CURL.Release"; $curl ) ]

Download a text from URL:

# start new transfer
Set Variable [$curl; Value:MBS("CURL.New")]
# set URL
Set Variable [$r; Value:MBS("CURL.SetOptionURL"; $curl; "")]
# run transfer
Set Variable [$ErrorCode; Value:MBS("CURL.Perform"; $curl)]
# get result as text and debug messages:
Set Variable [$TextResult; Value:MBS( "CURL.GetResultAsText"; $curl)]
Set Variable [$DebugMessages; Value:MBS( "CURL.GetDebugMessages"; $curl)]
# cleanup
Set Variable [$r; Value:MBS("CURL.Release"; $curl)]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 19th April 2020

CURL.LoadLibrary - CURL.NumberOfRunningTransfers