POST request
function Curl_post ($url ="', $postdata ="', $options =Array ()) {$ch=Curl_init ($url); curl_setopt ($ch, Curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_post,1); curl_setopt ($ch, Curlopt_postfields, $postdata); curl_setopt ($ch, Curlopt_timeout,5); curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE); if(!empty ($options)) {Curl_setopt_array ($ch, $options); } $data=curl_exec ($ch); Curl_close ($ch); return$data; }
GET request
function Curl_get ($url =", $options =Array ()) { $ch=curl_init ($url); curl_setopt ($ch, Curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_timeout,5); if (! empty ($options)) { Curl_setopt_array ($ch, $options); } $data=curl_exec ($ch); Curl_close ($ch); return $data; }
Two ways to get and post the Curl function (implement AJAX cross-domain invocation)