首页 >后端开发 >php教程 >获取接口的参数

获取接口的参数

WBOY
WBOY原创
2016-06-23 13:16:371352浏览

接口如下:
http://wthrcdn.etouch.cn/weather_mini?city=北京

从浏览器上直接输入可以获取返回值
但自己用了file_get_contents(),fopen()以及curl都获取不到返回值
初学,不知道是不是自己用法的问题。


回复讨论(解决方案)


$url = 'http://wthrcdn.etouch.cn/weather_mini?city=%E5%8C%97%E4%BA%AC';echo gzdecode(file_get_contents($url));
{"desc":"OK","status":1000,"data":{"wendu":"8","ganmao":"昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。","forecast":[{"fengxiang":"北风","fengli":"3-4级","high":"高温 9℃","type":"晴","low":"低温 -4℃","date":"16日星期二"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 9℃","type":"晴","low":"低温 -2℃","date":"17日星期三"},{"fengxiang":"北风","fengli":"3-4级","high":"高温 9℃","type":"晴","low":"低温 -2℃","date":"18日星期四"},{"fengxiang":"北风","fengli":"3-4级","high":"高温 7℃","type":"多云","low":"低温 -2℃","date":"19日星期五"},{"fengxiang":"无持续风向","fengli":"微风级","high":"高温 3℃","type":"晴","low":"低温 -5℃","date":"20日星期六"}],"yesterday":{"fl":"3-4级","fx":"北风","high":"高温 5℃","type":"晴","low":"低温 -4℃","date":"15日星期一"},"aqi":"41","city":"北京"}}

谢版主!!!!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn