Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Frontier::Client and getting right XML output

by inblosam (Monk)
on May 20, 2004 at 22:46 UTC ( #355112=perlquestion: print w/replies, xml ) Need Help??

inblosam has asked for the wisdom of the Perl Monks concerning the following question:

I am new at using RPC-XML. Some suggested to use Frontier::Client, and it seems pretty easy. My problem is constructing the arguments to pass through. I have a hash of key-value pairs, but when I debug it the XML request doesn't look like it should.
#!/usr/bin/perl -w use strict; use Frontier::Client; my $server = Frontier::Client->new('url' => ' +/service.php', 'encoding' => 'ISO-8859-1', 'debug' => 1); my $method = 'search'; my %paramfields = [{ 'this' => 'thisvalue', 'that' => 'thatvalue', 'something' => 'somevalue' }]; my $result = $server->call($method, %paramfields); print "My result is \n\n: $result\n";
And the debugger gives something like this:
---- request ---- <?xml version="1.0" encoding="ISO-8859-1"?> <methodCall> <methodName>searchres</methodName> <params> <param><value><array><data> <value><struct> <member><name>this</name><value><string>thisvalue</string></value></me +mber> <member><name>that</name><value><string>thatvalue</string></value></me +mber> <member><name>something</name><value><string>somevalue</string></value +></member> </struct></value> </data></array></value></param> </params> </methodCall>
What it should put out is something like this:
---- request ---- <?xml version="1.0" encoding="ISO-8859-1"?> <methodCall> <methodName>search</methodName> <params> <param> <value> <struct> <member> <name>this</name> <value> <string>thisvalue</string> </value> </member> <member> <name>that</name> <value> <string>thatvalue</string> </value> </member> <member> <name>something</name> <value> <string>somevalue</string> </value> </member> </struct> </value> <param> </params> </methodCall>
So the difference is the:
I need to get rid of those because it is throwing off the server and giving me an error that they can't find one of the key-value pairs.

Replies are listed 'Best First'.
Re: Frontier::Client and getting right XML output
by saintmike (Vicar) on May 20, 2004 at 23:29 UTC
    You're assigning an anonymous array, which contains an anonymous hash, to a hash called %paramfields. That's not right. I assume you want something like this:
    my @paramfields = ({ 'this' => 'thisvalue', 'that' => 'thatvalue', 'something' => 'somevalue' }); my $result = $server->call($method, @paramfields);
Re: Frontier::Client and getting right XML output
by rjray (Chaplain) on May 20, 2004 at 23:55 UTC

    First things first. This part right here:

    my %paramfields = [{ 'this' => 'thisvalue', 'that' => 'thatvalue', 'something' => 'somevalue' }];
    That is pretty messed up. You are assigning, to a hash table, a single value that is an array reference, whose first (and only) element is a hash reference. This array reference would be the key, but there is no value to go with it. I suspect that you meant to create an array @paramfields that has all the parameters you plan to pass to the call.

    Based on what you coded, the Frontier client did in fact encode it correctly.

    And just because it's me, I feel obligated to promote RPC::XML, which I feel is more actively maintained than Frontier (though I haven't been very active these past few months).


      Thanks, I need some fine-tuning to my array/hash skills. It works perfect now!!

      While I have your attention, I am a bit confused by the RPC::XML module and how to use it, as easy as with Frontier. I would happily use it if I knew how to!

      use RPC::XML; $req = RPC::XML::request->new('fetch_prime_factors', RPC::XML::int->new(985120528)); ... $resp = RPC::XML::Parser->new()->parse(STREAM); if (ref($resp)) { return $resp->value->value; } else { die $resp; }

      Where do I specify the server address ( and then can I just pass in the arguments like the array above? Where do I do that?


        Oh dear-- you shouldn't need to instantiate RPC::XML::Parser yourself. Look at the RPC::XML::Client class. You instantiate it with the HTTP URL of the service you want to talk to. Then you can make calls and get back data-objects as results.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://355112]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-06-25 17:02 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (83 votes). Check out past polls.