温馨提示×

php怎么编写https接口

九三
227
2021-03-03 14:07:15
栏目: 编程语言

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;

}

0