用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 am not sure where you are getting your info, but great topic. I needs to spend some time learning much more or understanding more. Thanks for fantastic information I was looking for this info for my mission.
共0条回复,点击查看回复
Hello! cheap viagra , cheap cialis generic , sildenafil generic india , cialis from india online pharmacy ,
共0条回复,点击查看回复
Your style is really unique compared to other folks I've read stuff from. deeaebgedede
共0条回复,点击查看回复
Jak korzystnie pozby? si? starych monet? Gdzie mo?na sprzeda? pami?tkowe monety? <a href=http://skupmonet.eu/>skup starych monet</a>
共0条回复,点击查看回复
skghost skghost 入门站长 普通 167#
http://hadsky.top/forum.php?mod=forumdisplay&fid=58 需要工具的可以过来下载

江西,赣州

共0条回复,点击查看回复
Hello! viagra cheap , viagra generic , cialis cheap , buy viagra ,
共0条回复,点击查看回复
Hello! viagra cheap , viagra generic , cialis cheap , buy viagra ,
共0条回复,点击查看回复
Hello! generic viagra , cialis cheap ,
共0条回复,点击查看回复
Pretty portion of content. I just stumbled upon your web site and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I will be subscribing in your augment or even I fulfillment you access constantly quickly.
共0条回复,点击查看回复
Pretty portion of content. I just stumbled upon your web site and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I will be subscribing in your augment or even I fulfillment you access constantly quickly.
共0条回复,点击查看回复
发布评论

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

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

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

取消