#!/usr/bin/perl -w

# server2.pl

use strict;
use IO::Socket;

my $server = IO::Socket::INET->new(
	LocalPort => 8080,
	Type => SOCK_STREAM,
    Reuse => 1,
    Listen => 5) or die "$@\n";

my $client;
     
while ( $client = $server->accept()){ 

    my $method = "";
    my $uri = "";
        
    while(<$client>){
        last if /^\r\n$/;

        if ( $_ =~ /^(GET|POST) (.*?) HTTP\// ){            
            $method = $1;
            $uri = $2;
        }
    }

    my $resp_html =<<HTML;
HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n
Método: $method
<br>
URI: $uri
<hr>
<form action='/' method='POST'>
    <input type='text' name='val1'>
    <input type='submit' value='Enviar POST'>
</form>
HTML

    print $client $resp_html;

    close($client);
}	