title: Mystery in Ruby sinatra
body: <p>I have the following Sinatra code:</p>
  
  <pre><code>post '/bucket' do
    # determine if this call is coming from filling out web form
    is_html = request.content_type.to_s.downcase.eql?('application/x-www-form-urlencoded')
  
    # If this is a curl call, then get the params differently
    unless is_html
        params = JSON.parse(request.env["rack.input"].read)
    end
  
    p params[:name]
  end
  </code></pre>
  
  <p>If I call this using Curl, <code>params</code> has values, but when this is called via a web form, then <code>params</code> is <code>nil</code> and <code>params[:name]</code> has nothing. I spent several hours figuring out why it happens and asked help from other people, but no one could really find out what is going on. </p>
  
  <p>One thing to note is, if I comment out this line:</p>
  
  <pre><code>params = JSON.parse(request.env["rack.input"].read)
  </code></pre>
  
  <p>then <code>params</code> has the correct value for "web-form" posting.</p>
  
  <p>Actually, the goal is to get the <code>params</code> value if this code is being called by CURL call, so I used:</p>
  
  <pre><code>params = JSON.parse(request.env["rack.input"].read)
  </code></pre>
  
  <p>but it messed up the web-form posting. Can anyone solve this mystery? </p>