php curl https 443,PHP CURL支持HTTP、HTTPS 请求亲测可用
廢話就不多說 直接上代碼,親測好用原生:
/**
* curl發送htpp請求
* 可以發送https,http,get方式,post方式,post數據發送
*/
public function dataRequest($url,$https=true,$method='get',$data=null)
{
//初始化curl
$ch = curl_init($url);
//字符串不直接輸出,進行一個變量的存儲
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//https請求
if ($https === true) {
//確保https請求能夠請求成功
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
}
//post請求
if ($method == 'post') {
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
}
//發送請求
$str = curl_exec($ch);
$aStatus = curl_getinfo($ch);
//關閉連接
curl_close($ch);
if(intval($aStatus["http_code"])==200){
return json_decode($str);
}else{
return false;
}
}
使用方法
$result = $this ->dataRequest('https://api.weixin.qq.com/cgi-bin/,true,'get',"");
//數值轉換
$object = json_decode( json_encode( $result),true);
$data['access_token'] = $object['access_token'];
*文章為作者獨立觀點,不代表上流閣立場
本文由 江風成 授權 上流閣 發表,并經上流閣編輯。轉載此文章須經作者同意,并請附上出處(上流閣)及本頁鏈接。原文鏈接https://www.o6c.com/web/2017/02/14/901.html
總結
以上是生活随笔為你收集整理的php curl https 443,PHP CURL支持HTTP、HTTPS 请求亲测可用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信红包怎么提现
- 下一篇: php curl hostname,ph