您好,登錄后才能下訂單哦!
<?php /** * 模擬post進(jìn)行url請(qǐng)求 * @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 //轉(zhuǎn)義 $ch = curl_init(); //抓取指定網(wǎng)頁 curl_setopt($ch, CURLOPT_URL,$postUrl); //設(shè)置header curl_setopt($ch, CURLOPT_HEADER, 0); //要求結(jié)果為字符串且輸出到屏幕上 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //規(guī)避SSL驗(yàn)證 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //跳過HOST驗(yàn)證 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //運(yùn)行curl $data = curl_exec($ch); curl_close($ch); return $data; } /** * 測(cè)試 * @param string $url */ function testAction() { $url = 'https://www.sojson.com/open/api/weather/json.shtml?city=北京'; $res = request_post($url); print_r($res); } testAction();
結(jié)果:
以上就是PHP-Curl模擬HTTPS請(qǐng)求(代碼實(shí)例)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注億速云其它相關(guān)文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。