InvalidURIError(错误的URI(不是URI?):https://api.flightstats.com/flex/schedules/rest/v1/json/from/VNS/to/DEL/departing/2017/ 8/7 APPID = 94f56975&安培; APPKEY = 0a0dc2b64f177ab866f0dba59342ffa4) 如何解决这个错误。使用httparty post方法。
flight = HTTParty.post(" https://api.flightstats.com/flex/schedules/rest/v1/json/from/# {params [:from]} / to /#{params [:to]} / departure /#{params [:year]} / #{PARAMS [:月]} /#?{PARAMS [:天]} APPID = 94f56975&安培; APPKEY = 0a0dc2b64f177ab866f0dba59342ffa4&#34)
答案 0 :(得分:0)
有两个问题。首先,网址包含#{params[:year]}
和#{params[:month]}
之间的空格,这会导致无效的网址。代码尝试POST
请求,但根据他们的documentation端点接受GET
请求。
将您的代码更改为:
HTTParty.get(
"https://api.flightstats.com/flex/schedules/rest/v1/json/from/"{params[:from]}/to/#{params[:to]}/departing/#{params[:year]}/#{params[:month]}/#{params[:day]}?appId=94f56975&appKey=0a0dc2b64f177ab866f0dba59342ffa4"
)