用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');

评论列表 评论
Once I initially commented I clicked the Notify me when new feedback are added checkbox and now each time a remark is added I get four emails with the same comment. Is there any way you possibly can remove me from that service? Thanks! egdeedbceafd
共0条回复,点击查看回复
Hello! cialis online ,
共0条回复,点击查看回复
Really informative article post.Thanks Again. Awesome.
共0条回复,点击查看回复
Thanks so much for sharing all with the awesome info! I am looking forward to checking out far more posts!
共0条回复,点击查看回复
emotionemotion
共0条回复,点击查看回复
I like what you guys are up too. Such smart work and reporting! Carry on the excellent works guys Ive incorporated you guys to my blogroll. I think it'll improve the value of my website
共0条回复,点击查看回复
Hello! viagra for sale without prescription , cialis for sale , viagra side effects dangers , cialis side effects tadalafil ,
共0条回复,点击查看回复
you have a terrific blog here! would you like to make some invite posts on my weblog?
共0条回复,点击查看回复
Great website! I am loving it!! Will be back later to read some more. I am taking your feeds also
共0条回复,点击查看回复
Hello! buy viagra online canada pharmacy , buy cialis , viagra sale , viagra , cheap generic viagra fast delivery ,
共0条回复,点击查看回复
发布评论

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

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

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

取消