在 Ruby on Rails 中读取头数据 [英] Reading header data in Ruby on Rails
本文介绍了在 Ruby on Rails 中读取头数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个 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屋!
查看全文