Created
September 12, 2008 17:44
-
-
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.
This file contains hidden or 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
#!/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