200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > php使用curl获取https请求办法

php使用curl获取https请求办法

时间:2018-10-18 21:11:40

相关推荐

php使用curl获取https请求办法

php教程|php手册

php,使用,curl,获取,https,请求,方法,php,使用,curl,获取,https,请求,方法,这篇

php教程-php手册

php使用curl获取https请求的方法

html5网页源码下载,t1 ubuntu,静态网页爬虫教程,php语音识别接口 php,SEO983lzw

这篇文章主要介绍了php使用curl获取https请求的方法,涉及curl针对https请求的操作技巧,非常具有实用价值,需要的朋友可以参考下

企业手机网站毕业源码,ubuntu获取r语言,地板下小爬虫,tmcl php,顺义淘宝seolzw

今日在做一个项目,需要curl获取第三方的API,对方的API是https方式的。

之前使用curl能获取http请求,但今天获取https请求时,出现了以下的错误提示:证书验证失败。

人人网源码下载,UBUNTU手机壁纸高级,tomcat打开网页失败,rust语言爬虫,创利树php,深企在线seo优化好不好lzw

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

解决方法为在curl请求时,加入:

代码如下:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在

curl https请求代码

代码如下:

<?php

/** curl 获取 https 请求

* @param String $url 请求的url

* @param Array $data 要發送的數據

* @param Array $header请求时发送的header

* @param int $timeout 超时时间,默认30s

*/

function curl_https($url, $data=array(), $header=array(), $timeout=30){

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在

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($data));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

$response = curl_exec($ch);

if($error=curl_error($ch)){

die($error);

}

curl_close($ch);

return $response;

}

// 调用

$url = ‘/api/message.php’;

$data = array(‘name’=>’fdipzone’);

$header = array();

$response = curl_https($url, $data, $header, 5);

echo $response;

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。