I'm trying to make an xml-rpc call from a coldfusion server. I found this xml-rpc cfc (Thanks, Brad Wood!) that formats the xml for the cfhttp call but I'm struggling with interpretting how to pass in any parameters besides the call name.
Here's the api documention using perl
This is my coldfusion code
<cfobject component="xmlrpc" name="c">
<cfset arr = arraynew(1)>
<cfset arrayappend(arr,"service.show")>
<cfset arrayappend(arr,myVIP)>
<cfset arrayappend(arr,myIP)>
<cfset arrayappend(arr,myPort)>
<cfset myxml = c.CFML2XMLRPC(arr,"call")>
<cfhttp url="#apiUrl#" method="POST">
<cfhttpparam name="request_body" value="#myxml#" type="XML">
</cfhttp>
The error message that I keep getting is:
Can't use string (myVIP...) as a HASH ref while "strict refs" in use at /home/...
So what I don't understand is how to translate the notation I see in perl of {parameter1=>'value1',parameter2=>'value2'} to the array that I'm passing into CFML2XMLRPC.
I figured it out and now it seems so obvious... You have to use a struct to hold the parameters and pass that into the array after the method string.
<cfset arr = arraynew(1)>
<cfset arrayappend(arr,"service.show")>
<cfset paramObj = structnew()>
<cfset paramObj['vip'] = myVIP>
<cfset paramObj['ip'] = myIP>
<cfset paramObj['port'] = myPort>
<cfset paramObj['show'] = "status/state">
<cfset arrayappend(arr,paramObj)>
I found the jquery xml-rpc documentation helpful to understanding how the xml should actually be formatted.
Note: the notation of
<cfset paramObj['ip'] = myIP>
vs
<cfset paramObj.ip = myIP>
is important since the latter will result in all uppercase for the parameter name in xmlrpc.cfc. (thanks to comment by Dave Merrill on this post)