title: HTTP post request via Ruby
body: <p>I'm very new to ruby and trying some basic stuff. When I send HTTP request to the server using: </p>
  
  <pre><code>curl -v -H "Content-Type: application/json" -X GET -d "{"myrequest":"myTest","reqid":"44","data":{"name":"test"}}" localhost:8099
  </code></pre>
  
  <p>My server sees JSON data as <strong>"{myrequest:myTest,reqid:44,data:{name:test}}"</strong> </p>
  
  <p>But when I send the request using the following ruby code:</p>
  
  <pre><code>require 'net/http'
  
  @host = 'localhost'
  @port = '8099'
  
  @path = "/posts"
  
  @body = ActiveSupport::JSON.encode({
      :bbrequest =&gt; "BBTest", 
      :reqid =&gt; "44", 
      :data =&gt; 
      {
          :name =&gt; "test"
      }
  })
  
  request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' =&gt;'application/json'})
  request.body = @body
  response = Net::HTTP.new(@host, @port).start {|http| http.request(request) }
  puts "Response #{response.code} #{response.message}: #{response.body}"
  </code></pre>
  
  <p>It sees it as <strong>"{\"bbrequest\":\"BBTest\",\"reqid\":\"44\",\"data\":{\"name\":\" test\"}}"</strong> and server is unable to parse it. Perhaps there are some extra options I need to set to send request from Ruby to exclude those extra characters? </p>
  
  <p>Can you please help. Thanks in advance.</p>