I have a test script where I run an HTTP server in the background, send some requests to it with LWP::UserAgent, and then try to check the results. The server works and IS getting called (have checked with a telnet, also inserting brutal 'die' statements into it), the UA gets the response, but my attempts to get the server to share info about the last request (using an "our" variable) are failing. The code is below. Any ideas?
Another odd thing here is that although the UA timeout is set to 1 second, doing a netstat after running the script shows there is something still waiting for a response on that port. It takes maybe 10 or 15 secs to stop.
#!/usr/local/bin/perl -w
use strict;
use LWP::UserAgent;
my $status = 'SOME_STATUS';
my $path = '/verify';
our $params;
# fake server to verify against
package MyServer;
use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);
sub handle_request {
my $self = shift;
my $cgi = shift;
my $p = $cgi->path_info();
$params = $cgi->Vars; #hardcoding this value doesn't help
print "HTTP/1.0 200 OK\r\n";
if ( $p eq $path ) {
print "Content-Type: text/plain\r\n";
print "Content-Length: ".length($status)."\r\n\r\n";
print "status\r\n";
}
}
package main;
my $pid = MyServer->new(8000)->background();
my $ua = LWP::UserAgent->new;
$ua->timeout( 1 );
my $ures = $ua->post('http://localhost:8000/verify', { v1 => 'abc', v2
+ => 'def' });
kill( 3, $pid);
print "params were : $params\n"; # expect to see { v1 => 'abc' ... }
Here's what we see on the command line:</p<
daniel@kinkyboots:~/work/engoi/trunk/Engoi$ ./test_server.pl
HTTP::Server::Simple: You can connect to your server at http://localho
+st:8000/
Use of uninitialized value $params in concatenation (.) or string at .
+/test_server.pl line 40, <DATA> line 16.
params were :
daniel@kinkyboots:~/work/engoi/trunk/Engoi$ netstat -ap|grep 8000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 localhost:8000 localhost:39238 TI
+ME_WAIT -