1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
function api_request($URL,$type,$params,$headers){ $ch = curl_init(); $timeout = 5; curl\_setopt($ch, CURLOPT\_URL, $URL); if($headers!=""){ curl\_setopt($ch, CURLOPT\_HTTPHEADER, $headers); }else { curl\_setopt($ch, CURLOPT\_HTTPHEADER, array('Content-type: text/json')); } curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, 1); curl\_setopt($ch, CURLOPT\_CONNECTTIMEOUT, $timeout); switch ($type){ case "GET" : curl\_setopt($ch, CURLOPT\_HTTPGET, true);break; case "POST": curl\_setopt($ch, CURLOPT\_POST,true); curl\_setopt($ch, CURLOPT\_POSTFIELDS,$params);break; case "PUT" : curl\_setopt ($ch, CURLOPT\_CUSTOMREQUEST, "PUT"); curl\_setopt($ch, CURLOPT\_POSTFIELDS,$params);break; case "DELETE":curl\_setopt ($ch, CURLOPT\_CUSTOMREQUEST, "DELETE"); curl\_setopt($ch, CURLOPT\_POSTFIELDS,$params);break; } $file\_contents = curl\_exec($ch); return $file_contents; curl_close($ch); }
?>
|