21,886
社区成员
发帖
与我相关
我的任务
分享
function https_request($url, $data = null, $referer = "", $type = "Content-Type: application/json", $cookie_file = "")
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, True);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, True);
if(!empty($referer)) {
curl_setopt($curl, CURLOPT_REFERER, $referer);
}
if ($data != null)
{
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
if(!empty($data)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
$arr = array();
$arr[] = 'Content-Length: ' . strlen($data);
if(!empty($type))
{
$arr[] = $type;
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $arr);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
if(!empty($cookie_file)) {
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
//echo $cookie_file;
}
$output = curl_exec($curl);
curl_close($curl);
return $output;
}