获取到API的结果截取想要的内容显示到页面
<?php
header("Content-type: text/html; charset=utf-8"); //解决中文乱码
$domain = $_GET['domain'];
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_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书下同
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
function testAction(){
$url = 'http://testapi.nabla.cn:8080/domain/whois';
$post_data['member_id'] = '380709';
$post_data['timestamp'] = '1641190236';
$post_data['signature'] = 'a985d8ccbb71ecdf716f02ae2b0749ca';
$post_data['keyword'] = $_GET['domain'];
//$post_data = array();
$res = request_post($url, $post_data);
echo $res;}
testAction();
?>
在浏览器输入地址文件.php?domain=域名+后缀(如baidu.com)