php怎么编写https接口

1178
2021/3/3 14:07:15
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

php怎么编写https接口

在php中使用curl库编写https接口,具体方法如下:

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;

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: php中json转字符串怎么实现