我是 RestClient 的新手,但我在网络上进行了深入搜索,但找不到任何帮助。
我的代码如下,并且正在运行,但我正在寻找更优雅的东西:
def get_from_mgmt(sub_path, par)
par += "&" unless par.empty?
path = ":http//#{USER}:#{PASSWORD}@#{HOST}/#{sub_path}.json?#{par}auth_token=#{AUTH_TOKEN}"
single_page = JSON.parse(RestClient.get path)
end
我在互联网上发现以下内容:
response = RestClient::Request.new(
:method => :get,
:url => @my_url + "/" + path.to_s,
:user => @my_user,
:password => @my_pass,
:headers => { :accept => :json,
:content_type => :json }
).execute
results = JSON.parse(response.to_str)
我喜欢它,但我不明白在哪里添加 AUTH_TOKEN 和其他参数。我已经尝试在标头中添加 auth_token 并且分开但在初始化中。
欢迎任何帮助!谢谢你。