zoukankan      html  css  js  c++  java
  • 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了。暂时没有搞清楚多久解封。

  • 相关阅读:
    AngularJS 包含HTML文件
    AngularJS 验证
    AngularJS html+DOM+ng-click事件
    表格边框css
    Ubantu下面命令听歌(豆瓣fm)
    AngularJS $http
    AngularJS过滤器
    Python-注册
    Python之内置函数
    生成手机号码代码
  • 原文地址:https://www.cnblogs.com/CryOnMyShoulder/p/9301478.html
Copyright © 2011-2022 走看看