Created
January 25, 2012 22:39
-
-
Save mattriley/1679326 to your computer and use it in GitHub Desktop.
Ruby HTTP POST request containing XML content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
I had to pass uri and not uri.path to Post.new. but this was great help, thanks!