调用http://apistore.baidu.com网站的接口
2016-07-23 13:59
357 查看
权声明:本文为博主原创文章,未经博主允许不得转载。
调用http://apistore.baidu.com网站的接口
curl方式
[php]
view plain
copy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
$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
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
$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;
调用http://apistore.baidu.com网站的接口
curl方式
[php]
view plain
copy
![](https://code.csdn.net/assets/CODE_ico.png)
$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
![](https://code.csdn.net/assets/CODE_ico.png)
$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;
相关文章推荐
- HDU5728 2016 Multi-University Training Contest 1 (递归+欧拉函数)
- http://blog.csdn.net/mindfloating/article/details/51534289
- UVA 11076-Add Again
- soft raid5阅读笔记之十四--resync和recovery的区别
- soft raid5阅读笔记之十三--异或操作
- soft raid5阅读笔记之十二--DMA相关
- 5. Longest Palindromic Substring && 214. Shortest Palindrome && 336. Palindrome Pairs
- soft raid5阅读笔记之十--状态标志
- soft raid5阅读笔记之九--MD中的superblock
- 373. Find K Pairs with Smallest Sums && 378. Kth Smallest Element in a Sorted Matrix
- soft raid5阅读笔记之七--MD中的bitmap
- maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
- Contains Duplicate
- POJ:1995 Raising Modulo Numbers(快速幂)
- 2016 Multi-University Training Contest 2 1006 Fantasia (hdu5739) 【割点 无向图dfs树 树形dp】
- 2016 Multi-university-training-contests-2 1006 点双连通分量
- 在QMainWindow添加控件,无法显示问题
- error: Setup script exited with error: command 'gcc' failed with exit status 1
- E - Doing Homework again hd 1789
- @tailrec注解与“蹦床”机制