MoneyWorks Manual
Curl_Exec (curlhandle)
Result Type: string or CURLcode number
Definition: Performs the CURL operation for the given curl object, and (usually) returns the response as a string. If you supply a write callback to collect response data, the result will be the completion CURLcode value.
The curlhandle will previously have been initialised with Curl_Init and had options set on it with Curl_SetOpt.
Example: Just getting the data
let ch = curl_init("http://cognito.co.nz/")
let data = curl_exec(ch)
syslog("data = " + data)
Example: Getting a result code as well. There are many ways a network request can fail, and it is useful to know why. While debugging, you can also check the log file for CURL errors.
property retval = ""
on MyWriteCallback(someData)
let retval = retval + someData
// optionally return false to abort
end
on Load
let ch = curl_init("http://cognito.co.nz")
curl_setopt(ch, CURLOPT_FOLLOWLOCATION, 1)
// by supplying a write callback, curl_exec will return
// a curl result code instead of the retrieved data
curl_setopt(ch, CURLOPT_WRITEFUNCTION, "MyWriteCallback")
let errorCode = curl_exec(ch)
syslog("CURL result = " + errorCode)
syslog("data = " + retval)
end
Availability: available within MWScript handlers.
See Also:
Base64Decode: String from a base64 encoding
Base64Encode: Base64 of a string
Curl_AsyncExec: Execute a CURL session on a background thread
Curl_Close: Finish with a CURL session
Curl_GetInfo: Get information about a CURL transfer
Curl_GetOpt: Get a handle from a curl handle
Curl_Init: Start a CURL session
Curl_StrError: Get an error message from a CURL object
URLEncode: Convert url unsafe characters in a string to "%xx”