在Ruby on Rails中读取标头数据 [英] Reading header data in Ruby on Rails
本文介绍了在Ruby on Rails中读取标头数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个API,该API将通过标头数据发送Facebook登录访问令牌中的信息.
I am making an API where in the access token for Facebook login will be sent in through header data.
如何从标题中读取此数据?
How do I read this data from the header?
推荐答案
request.headers["Content-Type"] # => "text/plain"
用您要阅读的标题名称替换"Content-Type".
replace "Content-Type" with the name of the header that you want to read.
Rails 4.2的更新
Update for Rails 4.2
在Rails 4.2中有两种获取它们的方法: 旧方法(仍在工作):
There are 2 ways to get them in Rails 4.2: Old way (still working):
request.headers["Cookie"]
新方法:
request.headers["HTTP_COOKIE"]
要获取带有请求的所有标头的哈希.
To get a Hash with all headers of the request.
request.headers
这篇关于在Ruby on Rails中读取标头数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文