溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么實(shí)現(xiàn)PHP-Curl模擬HTTPS請(qǐng)求

發(fā)布時(shí)間:2020-05-21 15:31:12 來源:億速云 閱讀:423 作者:鴿子 欄目:編程語言
<?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é)果:

怎么實(shí)現(xiàn)PHP-Curl模擬HTTPS請(qǐng)求

以上就是PHP-Curl模擬HTTPS請(qǐng)求(代碼實(shí)例)的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注億速云其它相關(guān)文章!

向AI問一下細(xì)節(jié)

免責(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)容。

AI