Skip to content

Instantly share code, notes, and snippets.

@ebot
Created September 12, 2008 17:44
Show Gist options
  • Save ebot/10480 to your computer and use it in GitHub Desktop.
Save ebot/10480 to your computer and use it in GitHub Desktop.
Client for working with servers that do not follow any web service standards where you have to create a custom xml document for the request.
#!/usr/bin/env ruby -wKU
require 'net/http'
require 'rexml/document'
server_name = 'server_name'
url = '/additional/html/pathing/'
in_file = 'input.xml'
user = {
:name => 'user_name',
:password => 'basic_authentication'
}
service_calls = {
:list_documents => 'ListDocuments.aspx',
:get_document => 'GetDocuments.aspx',
:get_object => 'GetDocuments.aspx'
}
# Load the xml file.
request = File.new in_file, 'r'
# Post the data to the server
Net::HTTP.start(server_name) do |http|
req = Net::HTTP::Get.new("#{url}#{service_calls[:list_documents]}")
req.basic_auth user[:name], user[:password]
req.body = request.read
req.content_type = 'text/xml'
puts "\nrequest:\n--------\n"
puts req.body
# Read in the respons and create a dom document.
response = http.request(req)
doc = REXML::Document.new (response.body)
puts "\nresponse:\n---------"
doc.write($stdout,0)
puts "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment