Created
August 13, 2013 15:44
-
-
Save base10/6222532 to your computer and use it in GitHub Desktop.
Here's some fun with monkey patching a class to see an XMLRPC response. I can't directly get at seeing what I'm going to send to an XMLRPC service with the XMLRPC::Client object itself. If I try to reach in and call 'create().methodCall', I'm told it's private. So, why not create a method where I can make a call and see what's going to happen, w…
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
$ ruby xmlrpc-test.rb | |
"<?xml version=\"1.0\" ?><methodCall><methodName>command</methodName><params><param><value><struct><member><name>expr</name><value><array><data><value><string>2 * 3</string></value></data></array></value></member></struct></value></param></params></methodCall>\n" |
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 | |
require 'xmlrpc/client' # part of stdlib | |
require 'pp' | |
host = "example.com" | |
path = "/cgi-bin/service.cgi" | |
port = 80 | |
request = XMLRPC::Client.new(host, path, port) | |
module XMLRPC | |
class Client | |
def call2_dummy_load(method, *args) | |
request = create().methodCall(method, *args) | |
end | |
end | |
end | |
begin | |
response = request.call2_dummy_load('command', { 'expr' => [ "2 * 3" ] }) | |
pp response | |
rescue XMLRPC::FaultException => e | |
puts "Error:" | |
puts e.faultCode | |
puts e.faultString | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment