在Rails中使用HTTParty gem时如何获取http标头?

时间:2017-02-13 15:21:22

标签: devise ruby-on-rails-5 httparty

我正在使用 gem'devise_token_auth' gem'gcparty'

发布操作后,我想从响应中获取ff标头:

示例:     HTTParty.post(“/ auth / sign_in”,@ options)

我需要:

access_token: response.headers['access-token'],
client: response.headers['client'],
expiry: response.headers['expiry'],
token_type: response.headers['token-type'],
uid: response.headers['uid']

请帮忙!

1 个答案:

答案 0 :(得分:0)

您可以访问HTTParty以这种方式返回的标题:

require 'httparty'

response = HTTParty.post("/auth/sign_in", @options)

puts response.headers

您还可以在此处查看示例:https://johnnunemaker.com/httparty/