牛骨文教育服务平台(让学习变的简单)
博文笔记

PHP之curl实现http与https请求的

创建时间:2017-04-28 投稿人: 浏览次数:3214
function httpGet($url){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$res=json_decode(curl_exec($curl),true);
	curl_close($curl);
	return $res;
}
function httpPost($url,$post_data){ 
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	// post数据
	curl_setopt($ch, CURLOPT_POST, 1);
	// post的变量
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	$output=json_decode(curl_exec($ch),true);
	curl_close($ch);
	return $data;
}
function httpsGet($url){
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);// https请求不验证证书和hosts
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	$res=json_decode(curl_exec($curl),true);
	curl_close($curl);
	return $res;
}
function httpsPost($url,$post_data){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	// post数据
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
	// post的变量
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	$output=json_decode(curl_exec($ch),true);
	curl_close($ch);
	return $output;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。