If i run this script and connect to 127.0.0.1 in my browser(s) it serves me the embedded form and accepts and displays the posted data from submitting that form:
#! perl -slw use strict; #use threads; use IO::Socket; $|++; my $page = do{ local $/; <DATA> }; my $s = IO::Socket::INET->new( Listen => 1, LocalPort => 80 ); while( my $c = $s->accept ) { printf "Connection accepted from %s\n", $c->peerhost; # async { my $req = <$c>; printf "Request received: %s\n", $req; my( $act, $url, $mode ) = split ' ', $req; if( $act eq 'GET' ) { if( $url eq '/' ) { print $c $page; } else { print $c '404 Not found'; } } elsif( $act eq 'POST' ) { my $read = 0; print $c '200 OK'; print $c ''; print $req; while( defined( $_ = <$c> ) and length() !=2 ) { printf "%s", $_; $read = $1 if $_ =~ m[Content-Length: (\d+)]; } print "\n", '=' x 20; my $post; read( $c, $post, $read ); print $post; } else { print $c '404 Not found'; } print $c ''; shutdown( $c, 2 ); close $c; # }->detach; } __DATA__ HTTP/1.0 200 OK Date: Mon, 28 Feb 2012 22:38:34 GMT Server: Perl/IOSocket/BrowserUk Content-Length: 3057 Connection: close Content-Type: text/html; charset=iso-8859-1 <html> <head> <title>A test</title> </head> <body> <h4>A test</h4> <p>A test paragraph. <form method=post> select: <select name=select><option value="2">2</option><option value= +"3">2</option><option value="4">4</option><option value="5">5</option +><option value="6">6</option><option value="7">7</option></select> <br />Radio: <input type="radio" name="radio" value="yes" /> Yes <inpu +t type="radio" name="radio" value="no" /> No <br />Radio2: <input type="radio" name="radio2" value="yes" />Yes<inpu +t type="radio" name="radio2" value="no" />No. <br />Select2: <select name=select2><option value="1">1</option><optio +n value="2">2</option><option value="3">3<option><option value="4">4< +/option><option value="5">5</option><option value="6">6</option><opti +on value="7">7</option><option value="8">8</option><option value="9"> +9</option><option value="10">10</option></select> <table border="1"> <tr><th>________</th><th>A</th><th>B</th><th>C</th></tr> <tr> <td>A</td> <td>-</td> <td> <select name="1.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="1.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>B</td> <td> <select name="2.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> <td> <select name="2.3"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> </tr> <tr> <td>C</td> <td> <select name="3.1"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td> <select name="3.2"><option value="1">1</option><option value="2"> +2</option><option value="3">3</option><option value="4">4</option><op +tion value="5">5</option><option value="6">6</option><option value="7 +">7</option><option value="8">8</option><option value="9">9</option>< +option value="10">10</option></select> </td> <td>-</td> </tr> </table> <input type="submit" value="Submit" /> </form> </body> </html>
(Note: this is drastically cut down toward the minimum, (the re-boot and trim cycle is tedious), that displays the following problem.)
However, if I connect to it via my external IP address -- port 80 forwarded to this machine via NAT -- the connect is accepted (at the server end), the browser spins its wheels for a few seconds and then the machine bluescreens! (The only non-hardware related bluescreen I've ever had with this OS.)
This happens regardless of the browser I use -- hence I exclude that.
A 'proper' httpd runs fine on this setup, hence I exclude the tcpip stack, OS etc.
Which brings me back to Perl and my own code. I've disabled the threading to exclude that red-herring from the picture. So that leaves something wrong in my handling of HTTP -- then why would it run fine locally? -- and IO::Socket -- ditto!
So, having excluded everything I can think of, and still having the problem, I throw it open to see what idiocies I am committing?
In reply to [OT]ish: HTTP/HTML/IO::Socket sanity check. by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |