以下是Net::Server::HTTP的简单脚本
#!/usr/bin/env perl
use strict;
use warnings;
use v5.12;
use HTTP::Headers;
use base qw(Net::Server::HTTP);
__PACKAGE__->run(port => localhost:8421 );
sub process_http_request
{
my ($self) = @_;
my $header = HTTP::Headers->new();
$header->content_type( text/html );
print $header->as_string() . "
"; # <- this works
# say $header->as_string() . "
"; # <- this doesn t work and I still have to add a newline
say "<!doctype html>";
say "<html>";
say "<head>";
say " <title>Test</title>";
say "</head>";
say "<body>";
say "<h1>Test</h1>";
say "</body>";
say "</html>";
}
我假设通过使用比如
,我可以绕过添加换行符的问题,但我必须添加它,它通过在每个HTTP字段中添加另一个换行符来破坏HTTP::Header
as_strings建议它是一个字符串。有人能解释一下这里到底发生了什么吗?