http get 天气
瞅两眼手册
很方便操作,直接方式 url 然后一个回调函数即可
直接照着例程写
local key = "**********"
local location = "zhengzhou"
local language = "zh-Hans"
local unit = "c"
local url = string.format("http://api.seniverse.com/v3/weather/now.json?key=%s&location=%s&language=%s&unit=%s", key, location, language, unit)
http.request("GET",url,nil,nil,nil,nil,cbFnc)
key是每个人私有的
然后回调函数
local function cbFnc(result,prompt,head,body)
log.info("testHttp.cbFnc",result,prompt)
if result and head then
for k,v in pairs(head) do
log.info("testHttp.cbFnc",k..": "..v)
end
end
if result and body then
log.info("testHttp.cbFnc","bodyLen="..body:len())
log.info("testHttp.cbFnc","body="..body)
end
end
把获取到的数据打印出来
下载看效果
河南加油,郑州加油