Hello Wise Monks,
UPDATE: Figured it out. Explanation below:
I am having a bit of a problem running a simple webserver on my local machine. Everything seems to be working fine except when I try and print out a simple message to the browser it dies on me. Any ideas on what could be causing this?
use HTTP::Daemon;
use HTTP::Status;
my $d = HTTP::Daemon->new(Listen => 5,
LocalAddr => 'localhost',
LocalPort => 80,
Proto => 'tcp') or die "Can't bin
+d : $@\n";
print "Please contact me at: <URL:", $d->url, ">\n";
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
if ($r->method eq 'GET') {
# dies right on this line
$c->send_response("Content-type: text/html\n\nHello Worl
+d");
}
else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c);
}
It's very possible I am misunderstanding the send_response function or how to interact with it.
Thank you in advance.
UPDATE: Figured it out, needed to add the
Content-type: text/html\n\n to the output. My mistake. Updated the code so that anyone who finds it has working code.
UPDATE2: In playing with HTML::Daemon below is better code to work with it. Just FYI:
use HTTP::Daemon;
use HTTP::Status;
require 'C:\\rrships\\default.cgi';
my $d = HTTP::Daemon->new(Listen => 5,
LocalAddr => 'localhost',
LocalPort => 80,
Proto => 'tcp') or die "Can't bin
+d : $@\n";
# print "Please contact me at: <URL:", $d->url, ">\n";
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
# print $r->url->path . "\n";
if ($r->method eq 'GET') {
my $response = HTTP::Response->new(200);
$response->content(&Hello_World($r->url->path, $r->url->
+query));
$response->header("Content-Type" => "text/html");
$c->send_response($response);
}
else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c);
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.