PHP-Curl模拟HTTPS请求
话不多说,直接上代码
<?php /** * 模拟post进行url请求 * @param string $url * @param array $postData */ function request_post($url = ‘‘, $postData = []) { if (empty($url)) { return false; } if ($postData != []) { $vars = http_build_query($postData, ‘‘, ‘&‘); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } $postUrl = $url; //初始化curl //转义 $ch = curl_init(); //抓取指定网页 curl_setopt($ch, CURLOPT_URL,$postUrl); //设置header curl_setopt($ch, CURLOPT_HEADER, 0); //要求结果为字符串且输出到屏幕上 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //规避SSL验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //跳过HOST验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //运行curl $data = curl_exec($ch); curl_close($ch); return $data; } /** * 测试 * @param string $url */ function testAction() { $url = ‘https://www.sojson.com/open/api/weather/json.shtml?city=北京‘; $res = request_post($url); print_r($res); } testAction();
结果:
PHP技术交流QQ群(各个大佬在线解答技术问题): 953618831
相关推荐
83911535 2020-11-13
曾是土木人 2020-10-31
yegen00 2020-10-21
soralaro 2020-10-11
katanaFlower 2020-09-18
wytzsjzly 2020-08-17
88407710 2020-08-17
ChinaJoeEE 2020-08-16
CyborgLin 2020-08-15
Blueberry 2020-08-15
PinkBean 2020-08-11
katanaFlower 2020-08-03
hunningtu 2020-07-30
阿债的方寸天地 2020-06-28
pingyan 2020-06-25
wytzsjzly 2020-06-25
阳光岛主 2020-06-25
阿债的方寸天地 2020-06-16