Curl is mainly used to create a REST request.
here is a simple example for a mail request using curl
$curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,$GLOBAL_SMS_URL); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,20); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $getit = json_decode($buffer, true);
now the first line of code is used to initialize the curl in the second line we define the remote url $ GLOBAL_SMS_URL (in my case)
Third line I determine the timeout in seconds
I pass the headers in the 4th line
one important thing if you want to go through the twisting body use this
curl_setopt($curl_handle, CURLOPT_POSTFIELDS,$json);
where $ json will contain the curl request body
or if you want to pass some parameter to the url
$data = array( "Username" => "56y5768", "Pwd" => "tr54656y", "PhoneNumber" => $phone, "PhoneMessage" => $text ); $getdata = http_build_query($data) . "\n"; $GLOBAL_SMS_URL = $SMS_API_BASE_URL.$getdata;
hope this helps
source share