title: Ruby on Rails net/http Post with '\r\n'
body: <p>I need to post some data in Rails to an external ASP.</p>
  
  <p>My curl command is working:</p>
  
  <pre><code>printf 'foo=bar\r\nparameter1=4711\r\nparameter2=4712' | curl --data-binary @- http://example.com/request.asp
  </code></pre>
  
  <p>How do I do this with net/http?</p>
  
  <p>Its important to keep the '\r\n' between the parameters.</p>
  
  <p>My coding so far:</p>
  
  <pre><code>uri = URI.parse('http://example.com/request.asp')
  
  http = Net::HTTP.new(uri.host, uri.port)
  
  req = Net::HTTP::Post.new(url.request_uri)
  req.set_form_data(params)
  response = http.request(req)
  </code></pre>
  
  <p>How do I set up params?</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>params = {
    'foo' =&gt; 'bar\r\n',
    'parameter1' =&gt; '4711\r\n',
    'parameter2' =&gt; '4712'
  }
  </code></pre>
  
  <p>But its not working. I need to encode it but how? </p>
  
  <p>I tried it with the URL encoded version of '\r\n': %0D%0A but it didn't work. Is there any way to send it as binary like curl does?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit: Thanks to your answers I found the solution:</strong></p>
  
  <pre><code>uri = URI.parse('http://example.com/request.asp')
  
  http = Net::HTTP.new(uri.host, uri.port)
  
  req = Net::HTTP::Post.new(url.request_uri)
  req.body = "foo=bar\r\nparameter1=4711\r\nparameter2=4712"
  response = http.request(req)
  </code></pre>
  
  <p>set_form_data a) encodes and b) adds "&amp;" both nothing I needed. Setting the body directly was the solution.</p>