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 -

In reply to test script for LWP::UA based code by danmcb

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.