php 通過curl header傳值
阿新 • • 發佈:2018-11-30
下面是自己整理的通過curl header傳值 方式是post
$url = 'http://www.***.com';//此處為傳值需要訪問的地址 $header = array('token:JxRaZezavm3HXM3d9pWnYiqqQC1SJbsU','language:zh','region:GZ'); $content = $data; $response = $this->data_ww($url, $header, $content); $data = json_decode($response, true);
//curl提交方法 public function data_ww($url, $header, $content){ $ch = curl_init(); if(substr($url,0,5)=='https'){ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳過證書檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 從證書中檢查SSL加密演算法是否存在 } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content)); $response = curl_exec($ch); if($error=curl_error($ch)){ die($error); } curl_close($ch); return $response; }