您的位置:首页 > 大数据 > 人工智能

调用http://apistore.baidu.com网站的接口

2016-07-23 13:59 357 查看
权声明:本文为博主原创文章,未经博主允许不得转载。
调用http://apistore.baidu.com网站的接口

curl方式

[php]
view plain
copy





$ch = curl_init();  
$url = 'http://apis.baidu.com/chazhao/ipsearch/ipsearch?ip=114.114.114.114';  
$header = array(  
    'apikey: your_baidu_appkey',  
);  
// 添加apikey到header  
curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
// 执行HTTP请求  
curl_setopt($ch , CURLOPT_URL , $url);  
$res = curl_exec($ch);  
  
var_dump(json_decode($res,true));  

file_get_contents方式

[php]
view plain
copy





$opt = array(    
    'http' => array(     
        'header' => "apikey:your_baidu_appkey"  
    )    
);    
    
$context = stream_context_create($opt);    
  
$url="http://apis.baidu.com/chazhao/ipsearch/ipsearch?ip=114.114.114.114";  
$html=file_get_contents($url,false,$context);  
echo $html; 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: