ruby – HTTParty选项参数无法正常运行
发布时间:2020-12-16 19:28:20 所属栏目:百科 来源:网络整理
导读:我正在设置一个可以生成LastFM API请求的应用程序. 这些是简单的get请求,我正在使用HTTParty gem. 我的功能如下: def get_albums self.class.base_uri "http://ws.audioscrobbler.com/2.0/" options = { :user = "Gerard1992",:method = "user.gettopalbums
我正在设置一个可以生成LastFM API请求的应用程序.
这些是简单的get请求,我正在使用HTTParty gem. 我的功能如下: def get_albums self.class.base_uri "http://ws.audioscrobbler.com/2.0/" options = { :user => "Gerard1992",:method => "user.gettopalbums",:api_key => Constants::LASTFM_API_KEY,:format => "json" } puts options.to_query self.class.get "/?#{options.to_query}",{} #options don't work end 上面显示的这段代码有效. get请求返回一组JSON.我的问题是这个/?#{options.to_query}看起来并不整洁.实际(现在为空{})选项参数也不存在.如何让HTTParty选项参数像它应该的那样工作? 这是我尝试过的,但两种情况都失败了: self.class.get "/",options self.class.get "/",options => options 我很感激帮助. 解决方法
HTTParty中查询参数的正确选项是:query,所以你想要的是:
self.class.get "/",query: options 您可以在the docs中查看所有可用参数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |