用Curl实现Post和Get请求,可绕过SSL验证

puyuetian 乐天 关注 九级站长 创始人
发表于PHP学习相关文章版块
今天撸码用到了Curl的post和get请求并需要绕过SSL验证,现将代码打包以备后用:

function request_by_curl($url, $post_data = '', $timeout = 30) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	//post提交,否则get
	if ($post_data != '') {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	}
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	curl_setopt($ch, CURLOPT_HEADER, false);
	//跳过SSL验证
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '0');
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '0');
	$file_contents = curl_exec($ch);
	curl_close($ch);
	return $file_contents;
}
用法举例:

//$result存储返回的数据
//post
$result = request_by_curl('http://www.hadsky.com', 'username=hadsky&password=hadsky.com');
//get
$result = request_by_curl('http://www.hadsky.com');

评论列表 评论
I have recently started a site, the info you provide on this website has helped me tremendously. Thanks for all of your time & work. The achievements of an organization are the results of the combined effort of each individual. by Vince Lombardi.
共0条回复,点击查看回复
Hello! fast ship generic viagra us ,
共0条回复,点击查看回复
reverse phone lookup cell free I wish to voice my gratitude for your generosity giving support to individuals
共0条回复,点击查看回复
reverse phone lookup cell free I wish to voice my gratitude for your generosity giving support to individuals
共0条回复,点击查看回复
I've been involved in the financial industry for many years in NZ speonly here cialis branding in the Korean market.
共0条回复,点击查看回复
Cedar avail for its use for degree generic buy pills cialis for us reviews is including.
共0条回复,点击查看回复
This makes?FFFFFFC2?FFFFFFA0super wow)) cialis fast activeonline more attractive for the and increases blood flow.
共0条回复,点击查看回复
Because here is a list of multiplayer games is that the leave was asked for more.
共0条回复,点击查看回复
Because here is a list of multiplayer games is that the leave was asked for more.
共0条回复,点击查看回复
However, if you take how to buy viagra with a high-fat meal, it will take longer for the drug to begin working.
共0条回复,点击查看回复
发布评论

评论: 用Curl实现Post和Get请求,可绕过SSL验证

已有0次打赏
(20) 分享
分享

请保存二维码或复制链接进行分享

取消