title: Rails 3 Post to external web service
body: <p>Lets say I have a blog post that a user is creating and I want to send all of the data to an external web service as XML with a specific schema so it can be ingested into that web service. </p>
  
  <p>I have been looking into the ActionDispatch::Request</p>
  
  <p>And I read this <a href="https://stackoverflow.com/questions/7340052/using-ruby-on-rails-to-post-json-xml-data-to-a-web-service">Using Ruby on Rails to POST JSON/XML data to a web service</a> post and answer</p>
  
  <p>However I got an error saying content_type was not a valid method for request. So I changed that line to call the header method and create a header for content-type with the appropriate information</p>
  
  <p>Ok... so now where to go?</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>url= URI.parse('http://10.29.3.47:8080/ingest')
  response = Net::HTTP::Post.new(url.path)
  request.headers["Content-Type"] = 'application/json'
  request.body = 'all of my xml data and schema which is far too long to type here'
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
  assert_equal '201 Created', response.get_fields('Status')
  </code></pre>
  
  <p>I get an error saying that request.body is also not a valid method call, but when I look at the API the only thing matching body is "body()" which does not take arguments. So how do I pass the content of my post to the web service? </p>
  
  <p>Thank you for the help!</p>