Perl XML-RPC output format/schema

110 views Asked by At

I'm writing a script in Perl to use two XML-RPC APIs. With one of them it works fine, with the other one i always get an empty result. After contacting the vendor of the second API, they sent me a PHP sample script to operate with the API. I couldn't find any differences in the setup, so after some debbuging i discovered that the XML sent differs by a few \ns:

<?xml version="1.0"?>
<methodCall>
<methodName>solde</methodName>
<params>
<param><value><struct>
<member><name>utilisateur</name><value><string>user</string></value></member>
<member><name>motDePasse</name><value><string>pass</string></value></member>
</struct></value>
</param>
</params>
</methodCall>

This is sent by the Perl script(i've tried with XML::RPC, Frontier::Client, RPC::XML - no luck in any case). The PHP script(the one that works) sends this:

<?xml version="1.0"?>
<methodCall>
<methodName>solde</methodName>
<params>
<param>
<value><struct>
<member><name>identification</name>
<value><struct>
<member><name>utilisateur</name>
<value><string>user</string></value>
</member>
<member><name>motdePasse</name>
<value><string>pass</string></value>
</member>
</struct></value>
</member>
</struct></value>
</param>
</params>
</methodCall>

The only difference between the two i see is a few newlines. I've sent POST requests with curl with the two XMLs, and in case #1 i get no result, in case #2 it works. Obviously the implementation of the second API(written in PHP btw) is more pretentious(reminder - in API #1 it works with the first XML, API #2 - no result).

What can i do, apart from generate the XML myself, to address this issue? Is there a way to tell any one of the existing Perl XML-RPC libraries to format the XML in such a way that the server will like it?

1

There are 1 answers

3
Borodin On BEST ANSWER

Your own XML is quite different. The contents of the parameter are correct

<value>
  <struct>
    <member>
      <name>utilisateur</name>
      <value>
        <string>user</string>
      </value>
    </member>
    <member>
      <name>motdePasse</name>
      <value>
        <string>pass</string>
      </value>
    </member>
  </struct>
</value>

but the version sent by the PHP code has this wrapped in a named structure, like this

<value>
  <struct>
    <member>
      <name>identification</name>


      <value>
        <struct>
          <member>
            <name>utilisateur</name>
            <value>
              <string>user</string>
            </value>
          </member>
          <member>
            <name>motdePasse</name>
            <value>
              <string>pass</string>
            </value>
          </member>
        </struct>
      </value>


    </member>
  </struct>
</value>

I hope this helps