Rails Note #9: Getting HTTP Headers
- I was trying to get the http headers dump from a mobile phone. So I quickly dump it in a log file to see its contents..
headers['Content-Type'] = 'text/xml; charset=utf-8' for header in request.env.select {|k,v| k.match("^HTTP.*")} logger.info(header[].split('_',2)[1] + ":" + header[1]) end |
Reference:
http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers
- However, please note that you can actually see everything from the request as parameters.
Parameters: {“MSAG-ADDRESS-PREFIX”=>”aSTARTa”, “format”=>”xml”, “protocol”=>”ussd”, “user-agent”=>”Jakarta Commons-HttpClient/3.0.1″, “WHOISD-ABONENT”=>”8613520747210″, “action”=>”menu”, “controller”=>”ussd”, “subscriberID”=>”8613520747210″, “WHOISD-USR”=>”-1″, “host”=>”wap.watago.mobi”, “WHOISD-USSD-MESSAGE”=>””, “content-length”=>”0″}
This means we can easily do..
@whoisd_abonent = params['WHOISD-ABONENT'] || nil |