PHP 实现curl post请求https协议 请求数据格式为 JSON : Map

public function curl($parameter = null, $url = null) {

$headers = array(“Content-type: application/json;charset=’utf-8′”,”Accept: application/json”,”Cache-Control: no-cache”,”Pragma: no-cache”);
$ch = curl_init(); //启动一个curl会话
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时
if (0 === strpos(strtolower($url), ‘https’)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在
}
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameter));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //获取返回值
$response = curl_exec($ch);
curl_close($ch);
return $response;
}

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注