http get請求:
function httpGet($url){$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$res=json_decode(curl_exec($curl),true);curl_close($curl);return $res;}
http post請求:
function httpPost($url,$post_data){ $ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// post資料curl_setopt($ch, CURLOPT_POST, 1);// post的變數curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);$output=json_decode(curl_exec($ch),true);curl_close($ch);return $data;}
https get請求:
function httpsGet($url){$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);// https請求不驗證認證和hostscurl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);$res=json_decode(curl_exec($curl),true);curl_close($curl);return $res;}
http get請求:
function httpsPost($url,$post_data){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// post資料curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗證認證和hostscurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);// post的變數curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);$output=json_decode(curl_exec($ch),true);curl_close($ch);return $output;}