您的位置:宽带测速网 > 网络安全 > php怎么编写https接口

php怎么编写https接口

2025-06-24 17:08来源:互联网 [ ]

在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;

}