[英]Is there a apache_request_headers alternatve for displaying HTTP Headers
[英]How to access HTTP headers in rails same as apache_request_headers?
我試圖訪問Rails 4中的一些自定義HTTP標頭。
令人沮喪的部分。 我可以在使用php apache_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)
有很多方法,但無法訪問標題。 我錯過了什么嗎?
我試圖訪問它的地方
HomeController的
class HomeController < ApplicationController
def index
end
end
ApplicationController的
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應該允許傳遞的頭文件
在site-available下的nginx.conf或站點配置文件中
location @app{
...
uwsgi_param HTTP_HEADER_NAME $http_header_name;
...
}
希望這可以幫助別人:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.