我正在尝试在 Rails 2.2.2 应用程序中获取 session_id
我检查了 Rails 文档并在语法上尝试了一些不同的东西。
当我执行 request.inspect 或 session.inspect 时,我看到 @session_id 有一个值
@session_id="BAh7CjoMd...",
但以下所有内容都返回 nil:
request.session[:session_id].inspect
session[:session_id].inspect
session['session_id'].inspect
session.inspect 的输出:
#<CGI::Session:0x104dff278
@write_lock=true,
@data={
:user_id=>nil,
:privilege_id=>nil,
:after_login=>{"action"=>"index", "controller"=>"home"},
:csrf_id=>"34a78413704ac92ee0eb276339b1af76", "flash"=>{}
},
@new_session=false,
@dbprot=[
#<CGI::Session::CookieStore:0x104dfe8a0
@secret="ee912af8f735b1acf19...",
@data={:
user_id=>nil,
:privilege_id=>nil,
:after_login=>{"action"=>"index", "controller"=>"home"},
:csrf_id=>"34a78413704ac92ee0eb276339b1af76", "flash"=>{}},
@digest="SHA1",
@original="BAh7CjoMd...",
@cookie_options={
"name"=>"_vendor_sandbox_session",
"http_only"=>true,
"secure"=>nil,
"expires"=>nil,
"domain"=>nil,
"path"=>"/"},
@session=#<CGI::Session:0x104dff278 ...>>],
@dbman=#<CGI::Session::CookieStore:0x104dfe8a0
@secret="ee912af8f735b1acf19...",
@data={
:user_id=>nil,
:privilege_id=>nil,
:after_login=>{
},
:csrf_id=>"34a78413704ac92ee0eb276339b1af76",
"flash"=>{}},
@digest="SHA1",
@original="BAh7CjoMd...",
@cookie_options={
"name"=>"_vendor_sandbox_session",
"http_only"=>true,
"secure"=>nil,
"expires"=>nil,
"domain"=>nil,
"path"=>"/"
},
@session=#<CGI::Session:0x104dff278 ...>>,
@session_id="BAh7CjoMd...",
@cgi=#<CGI:0x104f73c30
@cookies={
"_vendor_sandbox_session"=>["BAh7CjoMd..."],
},
@params={},
@output_hidden=nil,
@multipart=false,
@env_table={
"REQUEST_METHOD"=>"GET",
"SERVER_NAME"=>"localhost",
"SERVER_PORT"=>"3000",
"HTTP_CONNECTION"=>"keep-alive",
"QUERY_STRING"=>nil,
"PATH_INFO"=>"/login",
"SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2012-02-08)",
"REQUEST_URI"=>"http://localhost:3000/login",
"HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.5",
"GATEWAY_INTERFACE"=>"CGI/1.1",
"REMOTE_HOST"=>"127.0.0.1",
"REMOTE_USER"=>nil,
"SERVER_PROTOCOL"=>"HTTP/1.1",
"HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20100101 Firefox/17.0",
"HTTP_CACHE_CONTROL"=>"no-cache",
"HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"REMOTE_ADDR"=>"127.0.0.1",
"HTTP_COOKIE"=>_vendor_sandbox_session=BAh7CjoMdXNlcl9p...",
"HTTP_PRAGMA"=>"no-cache",
"HTTP_ACCEPT_ENCODING"=>"gzip, deflate",
"HTTP_HOST"=>"localhost:3000"},
@output_cookies=nil,
@stdin=#<StringIO:0x104f73c58