PHP post接口返回数据

摘要:
//解析中文乱码/***模拟post以生成url请求*@paramstring$url*@paramarray$post_data*/functionrequest_post($url='';$post_data=array()){if(空($url)||empty($post_dta))}{returnfalse,$curlPost=$post_ddata;$ch=curl_init();

分析过程

通过F12可知22.cn的域名查询页面像接口发送查询条件是POST的形式。 通过测试发现主要参数为atype=4 和keyword,  第二个参数不能带后缀。后缀有另外的参数。由于我关注的域名是康姆的,直接用atype和keywor对接口POST就行了

PHP post接口返回数据第1张

代码如下

<?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();

?>

返回结果

PHP post接口返回数据第2张

爱名网的查询页面只要短时间内访问超过50次 就GG了。暂时没有搞清楚多久解封。

免责声明:文章转载自《PHP post接口返回数据》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【原创】QT简单计算器动态链接库下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

mac安装git

终于换了本,记录安装插件的过程。 1.安装git: mac安装git,先安装brew,报错如下: curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused 原因是访问不到源,网络问题。 查了百度,最后成功的是使用了国内镜像: /bin/zsh...

【ipv6惹的祸】curl 超时

偶然发现 最近在公司日志平台 总是可以看到很多关于php curl的错误信息 Operation timed out after 0 milliseconds with 0 out of 0 bytes received Resolving timed out after 5514 milliseconds 非常奇怪,以前都是好的,使用wget获取也...

[转]CURL常用命令

From:http://www.cnblogs.com/gbyukg/p/3326825.html 常用参数 -v/--verbose 小写的v参数,用于打印更多信息,包括发送的请求信息,这在调试脚本是特别有用。 -m/--max-time <seconds> 指定处理的最大时长 -H/--header <header> 指定请求头...

Elasticsearch-索引新数据(创建索引、添加数据)

ES-索引新数据 0.通过mapping映射新建索引 CURL -XPOST 'localhost:9200/test/index?pretty' -d '{ "mappings": { "docs": { "_source": { "excludes": [ "query_content"...

pthread实现多线程查询(转)

导读:大多数网站的性能瓶颈不在PHP服务器上,因为它可以简单地通过横向增加服务器或CPU核数来轻松应对(对于各种云主机,增加VPS或CPU核数就更方便了,直接以备份镜像增加VPS,连操作系统、环境都不用安装配置),而是在于MySQL数据库。如果用 NoSQL 数据库,也许需要十次查询,才能处理完同样地业务逻辑。此时PHP多线程的作用非常明显,它可以同时执行...

php 访问java接口数据

$header = []; $header[] = 'Accept:application/json'; $header[] = 'Content-Type:application/json;charset=utf-8'; $data = $_GPC['mobile']; $ch = curl_init();...