Skip to content

Instantly share code, notes, and snippets.

@mhahl
Created May 10, 2015 22:33
Show Gist options
  • Save mhahl/9c0e6d027ab08de79f87 to your computer and use it in GitHub Desktop.
Save mhahl/9c0e6d027ab08de79f87 to your computer and use it in GitHub Desktop.
SOAP using net/http
# Thanks to:
# http://broadcast.oreilly.com/2008/12/creating-custom-soap-requests.html
require 'net/http'
require 'net/https'
# Create te http object
http = Net::HTTP.new('rpc.geocoder.us', 80)
http.use_ssl = false
path = '/service/soap/'
# Create the SOAP Envelope
data = <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:geocode xmlns:m="http://rpc.geocoder.us/Geo/Coder/US/">
<location xsi:type="xsd:string">1005 Gravenstein Highway North Sebastopol, CA 95472</location>
</m:geocode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
EOF
# Set Headers
headers = {
'Referer' => 'http://www.appfusion.net',
'Content-Type' => 'text/xml',
'Host' => 'rpc.geocoder.us'
}
# Post the request
resp, data = http.post(path, data, headers)
# Output the results
puts 'Code = ' + resp.code
puts 'Message = ' + resp.message
resp.each { |key, val| puts key + ' = ' + val }
puts data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment