#!/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;
}
####
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" ;
sum
1.12
4.12
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 = )
{
print $line;
}
close SOCKET or die "close: $!";
####
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
# create data
my $data = <<"START" ;
sum
1.12
4.12
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;
####
403 Forbidden
403 Forbidden
####
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
use LWP::Debug '+';
# create data
my $content = <<"START" ;
sum
1.12
4.12
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;