Rumah > pembangunan bahagian belakang > tutorial php > 获取接口的参数

获取接口的参数

WBOY
Lepaskan: 2016-06-23 13:16:37
asal
1359 orang telah melayarinya

接口如下:
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));
Salin selepas log masuk
{"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":"北京"}}

谢版主!!!!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan