php发送https请求,php post 请求https接口 -尊龙游戏旗舰厅官网
/**
* post请求https接口返回内容
* @param string $url [请求的url地址]
* @param string $post [请求的参数]
* @return string
*/
public function post_curls($url, $post)
{
$curl = curl_init(); // 启动一个curl会话
curl_setopt($curl, curlopt_url, $url); // 要访问的地址
curl_setopt($curl, curlopt_ssl_verifypeer, 0); // 对认证证书来源的检查
curl_setopt($curl, curlopt_ssl_verifyhost, 1); // 从证书中检查ssl加密算法是否存在
curl_setopt($curl, curlopt_useragent, $_server[‘http_user_agent‘]); // 模拟用户使用的浏览器
curl_setopt($curl, curlopt_followlocation, 1); // 使用自动跳转
curl_setopt($curl, curlopt_autoreferer, 1); // 自动设置referer
curl_setopt($curl, curlopt_post, 1); // 发送一个常规的post请求
curl_setopt($curl, curlopt_postfields, $post); // post提交的数据包
curl_setopt($curl, curlopt_timeout, 30); // 设置超时限制防止死循环
curl_setopt($curl, curlopt_header, 0); // 显示返回的header区域内容
curl_setopt($curl, curlopt_returntransfer, 1); // 获取的信息以文件流的形式返回
$res = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo ‘errno‘.curl_error($curl);//捕抓异常
}
curl_close($curl); // 关闭curl会话
return $res; // 返回数据,json格式
}
例子:
$data[‘param1‘]=‘红茶客:‘;
$data[‘param2‘]=‘明天有活动啦!~‘;
$url=‘https://api.xxxxx.com/push/pushall‘;
$huawei_res=$this->post_curls($url,$data);//返回json
$huawei_res=json_decode($huawei_res,true);
/*** post请求https接口返回内容*@paramstring $url [请求的url地址]*@paramstring $post [请求的参数]*@returnstring*/public functionpost_curls($url,$post){$curl=curl_init();//启动一个curl会话curl_setopt($curl,curlopt_url,$url);//要访问的地址curl_setopt($curl,curlopt_ssl_verifypeer,0);//对认证证书来源的检查curl_setopt($curl,curlopt_ssl_verifyhost,1);//从证书中检查ssl加密算法是否存在curl_setopt($curl,curlopt_useragent,$_server[‘http_user_agent‘]);//模拟用户使用的浏览器curl_setopt($curl,curlopt_followlocation,1);//使用自动跳转curl_setopt($curl,curlopt_autoreferer,1);//自动设置referercurl_setopt($curl,curlopt_post,1);//发送一个常规的post请求curl_setopt($curl,curlopt_postfields,$post);// post提交的数据包curl_setopt($curl,curlopt_timeout,30);//设置超时限制防止死循环curl_setopt($curl,curlopt_header,0);//显示返回的header区域内容curl_setopt($curl,curlopt_returntransfer,1);//获取的信息以文件流的形式返回$res=curl_exec($curl);//执行操作if(curl_errno($curl)) {echo‘errno‘.curl_error($curl);//捕抓异常}curl_close($curl);//关闭curl会话return$res;//返回数据,json格式}
原文:http://www.cnblogs.com/wz-ctt/p/7611974.html
总结
以上是尊龙游戏旗舰厅官网为你收集整理的php发送https请求,php post 请求https接口的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: