在PHP中使用curl库编写https接口,具体方法如下:function fetch_page($site,$url,$params=false){$ch = curl_init();$cookieFile = $site . '_coo
function fetch_page($site,$url,$params=false)
{
$ch = curl_init();
$cookieFile = $site . '_cookiejar.txt';
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HttpGET, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
if($params)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
curl_setopt($ch, CURLOPT_URL,$url);
$result = curl_exec($ch);
return $result;
}
--结束END--
本文标题: php怎么编写https接口
本文链接: https://www.lsjlt.com/news/113228.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0