Adding a curl library?

Hello guys, i need to use cURL for an API but i don’t really know if we can with CFX

I’m thinking that i can add a external library, but how to ?

I think i need this one : GitHub - Lua-cURL/Lua-cURLv3: Lua binding to libcurl

Thanks for reading.

1 Like

You don’t need curl bindings, there is already a built-in function to send http requests

https://docs.fivem.net/docs/scripting-reference/runtimes/lua/functions/PerformHttpRequest/

Thanks you !

i have tryed with the example given, but i got this error :

Do you know why ?

There is my code :

PerformHttpRequest(“https://api.top-serveurs.net/v1/votes/check?server_token=IFT5LY3J2U&playername=Luruk-Hai”, function (errorCode, resultData, resultHeaders)

print("Returned error code:" .. tostring(errorCode))

print("Returned data:" .. tostring(resultData))

print("Returned result Headers:" .. tostring(resultHeaders))

end)

(BTW i have to take the follows informations on this URL, with a GET method,

{“code”:404,“success”:false,“error”:“NotFound”,“message”:

That was my code in PHP (it actually work) :

$ip = “0.0.0.0.0”; //

$url = "https://api.top-serveurs.net/v1/votes/check-ip?server_token=IFT5LY3J2U&ip=" .$ip;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($curl);

$reponse = json_decode($result, TRUE);