cormanaz has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Bros. I'm trying to write a local HTTP::Daemon and process GET requests with CGI, but it's not working. My test code is
#!/usr/bin/perl -w use strict; use CGI; use HTTP::Daemon; use HTTP::Status; my $d = HTTP::Daemon->new(LocalPort => 8080) || die; while (my $c = $d->accept) { my $r = $c->get_request; my $q = new CGI($r); my @names = $q->param; foreach my $n (@names) { print "$n\t",$q->param($n),"\n"; } $c->close; undef($c); }

But when I call it with http://localhost:8080/test?foo=bar it prints HTTP::Request    HASH(0x2220b28)

What am I doing wrong?

TIA....Steve

Replies are listed 'Best First'.
Re: How to use CGI with HTTP:Daemon
by ikegami (Patriarch) on Dec 01, 2007 at 01:47 UTC
    I can't find any indication that CGI->new() can accept a HTTP::Request object as an argument.
Re: How to use CGI with HTTP:Daemon
by bingos (Vicar) on Dec 01, 2007 at 10:29 UTC
      That did it. Here's the working code
      #!/usr/bin/perl -w use strict; use CGI qw/:standard/; use HTTP::Daemon; use HTTP::Request::AsCGI; my $d = HTTP::Daemon->new(LocalPort => 8080) || die; while (my $c = $d->accept) { my $r = $c->get_request; my $cgi = HTTP::Request::AsCGI->new($r)->setup; my $q = CGI->new; my @names = $q->param; my $response; $response = $q->start_html; foreach my $k (@names) { my $val = $q->param($k); $response .= $q->p."key $k = $val"; } $response .= $q->end_html; $c->send_response("Content-type: text/html\n\n$response"); $c->close; undef($c); }