最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php中curl get/post 例子 (包括https协议)
时间:2022-06-24 19:52:34 编辑:袖梨 来源:一聚教程网
get 方法
| 代码如下 | 复制代码 |
| $url = "https://www.111cn.net /index.php?a=b&c=d&e=f&g=" . urlencode('王璐个人博客'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $output = curl_exec($ch); curl_close($ch); var_dump($output); |
|
post 方法
| 代码如下 | 复制代码 |
| $url = "https://www.111cn.net/ index.php"; $params = "a=b&c=d&e=f&g=" . urlencode('王璐个人博客'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_HEADER, 0); // 不要http header 加快效率 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_POST, 1); // post 提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $output = curl_exec($ch); curl_close($ch); var_dump($output); |
|
当请求https的数据时,会要求证书,这时候,加上下面这两个参数,规避ssl的证书检查
| 代码如下 | 复制代码 |
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts |
|
相关文章
- 星塔旅人怎么去白雾 星塔旅人反和谐方法介绍 10-26
- 星塔旅人怎么去圣光 星塔旅人反和谐相关设置分享 10-26
- 星塔旅人签到自选五星怎么选 五星角色选择建议分享 10-26
- 伊莫虹光星魔师捕捉攻略 10-26
- 原神秘闻馆奈芙尔私房钱获取攻略 10-26
- 二重螺旋图纸获取攻略 10-26