Skip to content

Instantly share code, notes, and snippets.

@gcimmino
Forked from mattriley/post_xml.rb
Created April 12, 2016 13:11
Show Gist options
  • Save gcimmino/e71d97a0d406a43b9e549648b6dc2248 to your computer and use it in GitHub Desktop.
Save gcimmino/e71d97a0d406a43b9e549648b6dc2248 to your computer and use it in GitHub Desktop.
Ruby HTTP POST request containing XML content
require 'net/http'
def post_xml url_string, xml_string
uri = URI.parse url_string
request = Net::HTTP::Post.new uri.path
request.body = xml_string
request.content_type = 'text/xml'
response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
response.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment