Skip to content

5.16 cURL Library

Claude Roux edited this page Dec 3, 2024 · 6 revisions

lispe_curl

back

This library is used to query data from the internet.

It exposes the following methods:

(deflib curl () Create a 'curl' object)
(deflib curl_passwrd (crl user pswd) Username and password)
(deflib curl_url (crl str (filename)) Loading an URL)
(deflib curl_proxy (crl str) Setting a proxy)
(deflib curl_execute (crl (filename)) Execution with storage in a file)
(deflib curl_options (crl str data) Initialisation of an option)
(deflib curl_set_function (crl function data) set a callback function with some data)
(deflib curl_set_headers (crl data)) set the header values for option CURLOPT_HTTPHEADER)

Here is an example:

(use 'lispe_curl)

(setq c (curl))

; mycallback is executed within the internal callback function in cURL
; d is the current value that have been received by this callback function
(defun mycallback (d result)
   (print d)
   (push result (trim d)
)

(setq result ())
(curl_set_function c 'mycallback result)

(curl_url c "https://wiki.c2.com/?LispMacro")

NB The option CURLOPT_HTTPHEADER takes as input values that have been initialized with curl_set_headers. The value you provide with curl_option for this option is not used by the function.

(setq cURL (curl))
; We initialize our headers
(curl_set_headers cURL "Content-Type: application/json")

; Which will be used by CURLOPT_HTTPHEADER. The value "headers" is useless here
(curl_options cURL "CURLOPT_HTTPHEADER" "headers")
Clone this wiki locally