收藏文章 楼主
用Curl实现Post和Get请求,可绕过SSL验证
版块:PHP学习相关文章   类型:精华   作者:乐天   查看:73127   回复:166   获赞:20   时间:2016-10-05 21:38:14
今天撸码用到了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');

有些梦虽然遥不可及,但并不是不可能实现。 
回复列表
默认   热门   正序   倒序
guest
163F
游客Lv0
Hello! viagra cheap , viagra generic , cialis cheap , buy viagra ,
 6   2017-05-02 00:48:04  回复
guest
159F
游客Lv0
I have recently started a web site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. There can be no real freedom without the freedom to fail. by Erich Fromm.
 5   2017-05-02 00:47:20  回复
guest
166F
游客Lv0
Hello! payday loans online , cialis , buy viagra , viagra , payday loan ,
 4   2017-05-14 17:21:57  回复
guest
160F
游客Lv0
I have recently started a web site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. There can be no real freedom without the freedom to fail. by Erich Fromm.
 4   2017-05-02 00:47:27  回复
guest
157F
游客Lv0
Hello! viagra cheap , viagra generic , cialis cheap , buy viagra ,
 4   2017-05-02 00:46:55  回复
xY874947899
2F
小亦Lv16
然而我并没有看懂emotion
 4   2016-10-07 13:36:49  回复
guest
165F
游客Lv0
Hello! payday loans online , cialis , buy viagra , viagra , payday loan ,
 3   2017-05-14 17:21:52  回复
guest
162F
游客Lv0
I have recently started a web site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. There can be no real freedom without the freedom to fail. by Erich Fromm.
 3   2017-05-02 00:47:49  回复
guest
161F
游客Lv0
I have recently started a web site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. There can be no real freedom without the freedom to fail. by Erich Fromm.
 3   2017-05-02 00:47:37  回复
guest
158F
游客Lv0
I have recently started a web site, the info you provide on this site has helped me greatly. Thank you for all of your time & work. There can be no real freedom without the freedom to fail. by Erich Fromm.
 3   2017-05-02 00:47:11  回复

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

暂无用户组
退出
等级:0级
天豆:
游客:

公告

近期本站被人为恶意注册及发布垃圾帖,本站已开启普通用户发帖审核功能,VIP系列用户组不受影响,一但发现发布违法或垃圾帖的用户,该用户账号将会被永久封号,请大家共同维护互联网环境,共创美好互联网未来。

永久免费,购授权享豪礼

3年个人版授权+1940天豆仅需194元

终身个人版授权+3880天豆仅需388元

3年尊享版授权+13580天豆仅需1358元

终身尊享版授权+27160天豆仅需2716元

Powered by HadSky 7.9.3

©2015 - 2021 HadSky

购买产品 用户文档 加入QQ群 授权查询 网站绑定 客户案例 陕ICP备13005805号

您的IP:18.212.120.195,2021-11-27 14:01:26,Processed in 0.04222 second(s).

支持原创软件,抵制盗版,共创美好明天!
头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息
已有0次打赏
(20) 分享
分享

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

取消