Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  

CURL.New

Start a new CURL easy session.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
CURL 2.5 Yes Yes Yes Yes Yes

MBS( "CURL.New" )

Parameters

none

Result

A new CURL handle.

Description

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.Cleanup 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.

Examples

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 [$r; MBS("CURL.SetOptionURL"; $curl; "https://example.test/wc-api/v2/products") ]
# make a post with some data
Set Variable [$r; MBS("CURL.SetOptionPost"; $curl; 1) ]
Set Variable [$r; MBS("CURL.SetOptionPostFields"; $curl; "{product:{...}}"; "UTF-8") ]
# set credentials
Set Variable [$r; MBS("CURL.SetOptionUsername"; $curl; "consumer_key") ]
Set Variable [$r; MBS("CURL.SetOptionPassword"; $curl; "consumer_secret") ]
# add header option
Set Variable [$r; MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/json", "Expect:" ) ]
# disable security for this demo:
Set Variable [$r; MBS( "CURL.SetOptionSSLVerifyHost"; $curl; 0 ) ]
Set Variable [$r; MBS( "CURL.SetOptionSSLVerifyPeer"; $curl; 0 ) ]
# with log messages
Set Variable [$r; MBS( "CURL.SetOptionVerbose"; $curl; 1 ) ]
# run it!
Set Variable [$Error; MBS( "CURL.Perform"; $curl ) ]
# check debug messages
Set Variable [$Messages; MBS("CURL.GetDebugAsText"; $curl) ]
# check result
Set Variable [$Output; MBS("CURL.GetResultAsText"; $curl) ]
# and cleanup
Set Variable [$r; MBS( "CURL.Cleanup"; $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; "https://www.mbsplugins.eu/")]
# 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.GetDebugAsText"; $curl)]
# cleanup
Set Variable [$r; Value:MBS("CURL.Cleanup"; $curl)]

See also

Example Databases


CURL.List   -   CURL.NumberOfRunningTransfers

Feedback: Report problem or ask question.




Links
MBS Xojo blog