Skip to content

Instantly share code, notes, and snippets.

@tgds
Forked from mattriley/post_xml.rb
Last active August 29, 2016 17:22
Show Gist options
  • Save tgds/f9fb15d9d43b3c6ac54700f1913573e4 to your computer and use it in GitHub Desktop.
Save tgds/f9fb15d9d43b3c6ac54700f1913573e4 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
request.body = xml_string
request.content_type = 'text/xml'
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')
response = http.request request
response.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment