Home > rails, ruby > Rails Note #9: Getting HTTP Headers

Rails Note #9: Getting HTTP Headers

November 20th, 2008 rupert Leave a comment Go to comments

1. 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[0].split('_',2)[1] + ":" + header[1])
    end

Reference:
http://tonycode.com/wiki/index.php?title=Dumping_HTTP_Headers

2. 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
Categories: rails, ruby Tags: ,
  1. No comments yet.
You must be logged in to post a comment.