note 116696 deleted from book.curl by didou

From: Date: Fri, 13 Feb 2015 00:57:42 +0000
Subject: note 116696 deleted from book.curl by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201715@lists.php.net to get a copy of this message
Note Submitter: m dot rizwan_47 at yahoo dot com ---- function make_curl_request($endpoint, $params=array(), $type){ if($type=='POST' or $type=='JSON'){ $url = $endpoint; }else{ $url = $endpoint.'?'.http_build_query($params); } $curl = curl_init(); $opts = array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_USERAGENT => 'Codular Sample cURL Request', CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0 ); if($type=='POST' or $type=='JSON'){ if($type=='JSON'){ $opts[CURLOPT_POSTFIELDS] = json_encode($params); $opts[CURLOPT_HTTPHEADER] = array( 'Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($params)) ); }else{ $opts[CURLOPT_POSTFIELDS] = $params; } $opts[CURLOPT_POST] = 1; } curl_setopt_array($curl, $opts); $resp = curl_exec($curl); curl_close($curl); return $resp; } For making JSON requests too

« previous php.notes (#201715) next »