Modules/cURL/curl perform: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{ModuleFunction|cURL}} Let cURL do his work now, by call this function. ==Syntax== <syntaxhighlight lang="lua"> curl_perform(curl handler[, table callbackfunctions]) </syntaxhighlight> ==Requ...")
 
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
curl_perform(curl handler[, table callbackfunctions])
curlPerform(curl handler)
</syntaxhighlight>
</syntaxhighlight>


==Required arguments==
==Required arguments==
* '''curl''' The curl handler
* '''curl''' The curl handler
==Optional arguments==
* '''callbackfunctions''' A set with callback functions;
<syntaxhighlight lang="lua">
local callbacks = {
    writefunction = function(data)
        -- This is the actual return data from the call
    end,
    headerfunction = function(data)
        -- This is the return headers from the call. (the webserver you call sends those headers back)
    end
}
</syntaxhighlight>


==Returns==
==Returns==
Returns a curl code, if the code is CURLE_OK then your good. Other wise pass this code to curl_strerror, and then you will know what is going on.
Returns a curl code, if the code is CURLE_OK then your good. Other wise pass this code to curl_strerror, and then you will know what is going on.
On a success call it will return the data as a second argument.


==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
curl = curl_init();
curl = curlInit();
if not curl then
if not curl then
     outputDebugString("Can't connect to http://mtasa.com/ with cURL");
     outputDebugString("Can't connect to http://mtasa.com/ with cURL");
else
else
     curl_setopt(curl, CURLOPT_URL, curl_escape(curl, "http://mtasa.com/"));
     curlSetopt(curl, CURLOPT_URL, curlEscape(curl, "http://mtasa.com/"));
     curl_perform(curl, {
     result, data = curlPerform(curl);
        writefunction = function(html)
    if result == CURLE_OK then
            -- Hell what should i do with html? :S
         print(data)
         end,
     end
     });
     curlClose(curl);
     curl_close(curl);
end
end
</syntaxhighlight>
</syntaxhighlight>
Line 46: Line 33:
==See also==
==See also==
{{Modules/cURL/functions}}
{{Modules/cURL/functions}}
[[Category:Modules]]

Latest revision as of 11:11, 22 June 2014


Package-x-generic.png This function is provided by the external module cURL. You must install this module to use this function.

Let cURL do his work now, by call this function.

Syntax

curlPerform(curl handler)

Required arguments

  • curl The curl handler

Returns

Returns a curl code, if the code is CURLE_OK then your good. Other wise pass this code to curl_strerror, and then you will know what is going on. On a success call it will return the data as a second argument.

Example

curl = curlInit();
if not curl then
    outputDebugString("Can't connect to http://mtasa.com/ with cURL");
else
    curlSetopt(curl, CURLOPT_URL, curlEscape(curl, "http://mtasa.com/"));
    result, data = curlPerform(curl);
    if result == CURLE_OK then
        print(data)
    end
    curlClose(curl);
end


See also