#!/usr/bin/perl
use strict;
use Socket;
use IO::Handle;
# initialize host and port
my $host = 'localhost';
my $port = 8999;
# my $port = 80;
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: $!";
SOCKET->autoflush(1);
# 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\n" . $data ;
print $content ;
print SOCKET "$content\n" or die "print SOCKET: $!";
print "waiting for response\n";
my $line;
while ($line = )
{
print $line;
}
close SOCKET or die "close: $!";
####
POST /quotes.cgi HTTP/1.0
Host: localhost
Content-Type: text/xml
Content-length: 209
sum
1.12
4.12
waiting for response
HTTP/1.1 403 Forbidden
Date: Mon, 15 Dec 2008 16:09:28 GMT
Server: libwww-perl-daemon/5.818
Content-Type: text/html
Content-Length: 53
403 Forbidden
403 Forbidden
####
while ($conn = $self->accept) {
my $rq = $conn->get_request;
if ($rq) {
if ($rq->method eq 'POST' && $rq->url->path eq '/RPC2') {
${*$self}{'response'}->content(${*$self}{'decode'}->serve($rq->content, ${*$self}{'methods'}));
$conn->send_response(${*$self}{'response'});
} else {
print STDERR "got an invalid request\n";
$conn->send_error(RC_FORBIDDEN);
}
}
$conn->close;
$conn = undef; # close connection
}
####
#!/usr/bin/perl
use strict;
use Socket;
use IO::Handle;
# initialize host and port
my $host = 'localhost';
my $port = 8999;
# my $port = 80;
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: $!";
SOCKET->autoflush(1);
# create data
my $data = <<"START" ;
sum
1.12
4.12
START
my $header = <<"START" ;
POST /RPC2 HTTP/1.0
Host: localhost
Content-Type: text/xml
START
$header .= "Content-length: " . length($data) ;
my $content = $header. "\n\n" . $data ;
print $content ;
print SOCKET "$content\n" or die "print SOCKET: $!";
print "waiting for response\n";
my $line;
while ($line = )
{
print $line;
}
close SOCKET or die "close: $!";
####
POST /RPC2 HTTP/1.0
Host: localhost
Content-Type: text/xml
Content-length: 209
sum
1.12
4.12
waiting for response
HTTP/1.1 200 OK
Date: Mon, 15 Dec 2008 16:17:46 GMT
Server: libwww-perl-daemon/5.818
Content-Length: 128
Content-Type: text/xml
5.24