I'm using the Savon gem to make a SOAP request using code similar to what's below. It's working, but I would like to view/capture the request XML without actually making a call to their server. I can view it now after a request is made by sticking a debugger line after the request and inspecting the client variable.
Does anyone know of a way to view the request XML without actually making a request? I want to be able to validate the XML against a schema using Cucumber or Rspec.
client = Savon::Client.new do |wsdl, http| wsdl.document = "http://fakesite.org/fake.asmx?wsdl" end client.request(:testpostdata, :xmlns => "http://fakesite.org/") do soap.header = { :cAuthentication => {"UserName" => "MyName", "Password" => "MyPassword" } } soap.body = { :xml_data => to_xml } end
Using Savon 2 I do it this way, write a method that return the request body from the client.
client = Savon::Client.new(....)
this is not mentioned in the documentation
def get_request # list of operations can be found using client.operations ops = client.operation(:action_name_here) # build the body of the xml inside the message here ops.build(message: { id: 42, name: "Test User", age: 20 }).to_s end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With