Man of few words said, directly on the code
<?php /** * Simulation for post request 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 ; // initialize escape curl // $ CH = curl_init (); // fetch a given page curl_setopt ( $ CH , CURLOPT_URL to, $ posturl ); // set header curl_setopt ( $ CH , CURLOPT_HEADER, 0 ); // requires a string and outputs the result to the screen curl_setopt ( $ CH , CURLOPT_RETURNTRANSFER,. 1 ); // circumvent SSL authentication curl_setopt ( $ CH , CURLOPT_SSL_VERIFYPEER, to false ); // skip verification HOST curl_setopt (CH $ , CURLOPT_SSL_VERIFYHOST, to false ); // Run curl $ Data = the curl_exec ( $ CH ); curl_close($ch); return $data; } /** * Test * @param string $url */ function testAction() { $url = 'https://www.sojson.com/open/api/weather/json.shtml?city=北京'; $res = request_post($url); print_r($res); } testAction ();
result:
PHP technical exchange QQ group (each Gangster online to answer technical questions): 953 618 831