Dear Monks
I'm trying to send XML to an XMLRCP server and for some reason it doesn't work

Here is the code (copied from the web) for the XMLRPC server:
#!/usr/bin/perl # sum() server use strict; use warnings; use Frontier::Daemon; my $d = Frontier::Daemon->new( LocalPort => 8999, methods => { sum => \&sum, }, LocalAddr => 'localhost' ) or die "Cannot start HTTP server $!\n" ; sub sum { my ($arg1, $arg2) = @_; print "summing $arg1 en $arg2\n"; return $arg1 + $arg2; }
Client
use strict; use Socket; # initialize host and port my $host = 'localhost'; my $port = 8999; my $proto = getprotobyname('tcp'); # get the port address my $iaddr = inet_aton($host); my $paddr = sockaddr_in($port, $iaddr); # create the socket, connect to the port socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCKET, $paddr) or die "connect: $!"; # create data my $data = <<"START" ; <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> START my $header = <<"START" ; POST /quotes.cgi HTTP/1.0 Host: localhost Content-Type: text/xml START $header .= "Content-length: " . length($data) ; my $content = $header. "\n" . $data ; print $content ; print SOCKET "$content\n" ; my $line; while ($line = <SOCKET> ) { print $line; } close SOCKET or die "close: $!";
I get the impression the client can connect, and probably sends the xml, but the server doesn't respond

Here is code from an other client I've tested:
use LWP::UserAgent; my $ua = new LWP::UserAgent; # create data my $data = <<"START" ; <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> START my $header = <<"START" ; POST /quotes.cgi HTTP/1.0 Host: localhost Content-Type: text/xml START $header .= "Content-length: " . length($data) ; my $content = $header. "\n" . $data ; print $content ; my $response = $ua->post('http://localhost:8999', $content) ; print $response->content;
Now I get a response
<title>403 Forbidden</title> <h1>403 Forbidden</h1>
Only when I used Frontier::Client the client worked!!
Any suggestions why these two attemps failed ?

Thnx
LuCa

UPDATE: thnx for the replies. With the input below I managed to get the second client app to work too :)
#!/usr/bin/perl -w use strict; use LWP::UserAgent; my $ua = new LWP::UserAgent; use LWP::Debug '+'; # create data my $content = <<"START" ; <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param> <value><double>1.12</double></value> </param> <param> <value><double>4.12</double></value> </param> </params> </methodCall> START print $content ; my $req = HTTP::Request->new (POST => 'http://10.0.0.2:8999/RPC2'); $req->header('Content-Type' => 'text/xml'); $req->content($content); my $response = $ua->request($req); print $response->content;

In reply to XMLRPC - doing it the hard way by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.