PHP post接口返回數據


分析過程

通過F12可知22.cn的域名查詢頁面像接口發送查詢條件是POST的形式。 通過測試發現主要參數為atype=4 和keyword,  第二個參數不能帶后綴。后綴有另外的參數。由於我關注的域名是康姆的,直接用atype和keywor對接口POST就行了

 

代碼如下

<?php
header("Content-type: text/html; charset=utf-8"); //解決中文亂碼
/**
     * 模擬post進行url請求
     * @param string $url
     * @param array $post_data
     */
    function request_post($url = '', $post_data = array()) {
        if (empty($url) || empty($post_data)) {
            return false;
        }
       

        $postUrl = $url;
        $curlPost = $post_data;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定網頁
        curl_setopt($ch, CURLOPT_HEADER, 0);//設置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求結果為字符串且輸出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_ENCODING, "");//解壓
        //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip, deflate,flate'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不驗證證書下同
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不驗證證書下同
        $data = curl_exec($ch);//運行curl
        curl_close($ch);
         //$res=json_decode($data,true);
        return $data;
    }
    
    
    function testAction(){
        $url = 'https://am.22.cn/ajax/taoym/default.ashx?t=0.5844175927806412';
        $post_data['atype']       = '4';
        $post_data['keyword']      = 'haha';
        //$post_data = array();
        $res = request_post($url, $post_data);       
       echo $res;
    }
testAction();

?>

 

返回結果

愛名網的查詢頁面只要短時間內訪問超過50次 就GG了。暫時沒有搞清楚多久解封。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM