Client#!/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; }
I get the impression the client can connect, and probably sends the xml, but the server doesn't responduse 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: $!";
Now I get a responseuse 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;
Only when I used Frontier::Client the client worked!!<title>403 Forbidden</title> <h1>403 Forbidden</h1>
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |