我正在尝试在Rails 4中访问一些自定义HTTP标头。
令人沮丧的部分。使用phpapache_request_headers()
函数时,我可以获取该自定义标头,但无法在Rails 4中访问该标头。
到目前为止我尝试过的东西。
request.headers
request.headers["header_name"]
request.headers["HTTP_header_name"]
request.headers.env["header_name"]
headers = ActionDispatch::Http::Headers.new(env)
还有更多方法,但是无法访问标头。那我想念什么吗?
我试图访问此的地方
家庭控制器
class HomeController < ApplicationController
def index
end
end
应用程序控制器
class ApplicationController < ActionController::Base
before_action :sso_handler, :only => [:index, :show]
...
def sso_handler
//all above commands i tried here.
end
end
所以我不知道为什么我可以在php中访问标头,为什么不能在Rails 4中访问。
终于找到了原因。这是nginx的问题。Nginx不允许标题通过。需要指定nginx应该允许像这样传递的标题
在nginx.conf或sites-available下的site config文件中
location @app{
...
uwsgi_param HTTP_HEADER_NAME $http_header_name;
...
}
希望这可以帮助某人:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句