Director of Cloud Engineering @ Team8Solutions, Freelancer
SOAP Request From Ruby Without Savon
Send SOAP request from ruby net/http without using Savon gem
You would have seen everyone is using Savon gem for sending SOAP request. But what if the service is using SOAP 1.1.
You might want to write your own http request. Here is the way to send request with SOAP envelope body.
require'net/https'require'uri'require'nokogiri'# Create the http objecturl="http://www.webservicex.net/globalweather.asmx?WSDL"uri=URI.parse(url)http=Net::HTTP.new(uri.host,uri.port)http.use_ssl=false# Raw SOAP XML to be passed# TODO : Date should be dynamicdata=<<-EOF<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetWeather xmlns="http://www.webserviceX.NET"> <CityName>Madras</CityName> <CountryName>India</CountryName> </GetWeather> </soap:Body></soap:Envelope>EOF# # Set Headers# SOAPAction is mandatoryheaders={'Content-Type'=>'text/xml; charset=utf-8','SOAPAction'=>"http://www.webserviceX.NET/GetWeather"}result=http.post(uri.path,data,headers)# Parsedoc=Nokogiri::XML(result.body)doc.remove_namespaces!# Remove namespaces from xml to make it cleanpdoc