HTTP-Request-FromTemplate
view release on metacpan or search on metacpan
use HTTP::Request::FromTemplate;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
# A request, snarfed from your network monitor logs:
my $template = <<TEMPLATE
POST http://[% host %][% path %][% query %] HTTP/1.1
Host: [% host %]
Connection: keep-alive
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
User-Agent: QuickTime (qtver=5.0.2;os=Windows NT 5.1)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Keep-Alive: 300
Referer: http://[% host %][% path %][% query %]
TEMPLATE
my $t = HTTP::Request::FromTemplate->new(template => $template);
README.mkdn view on Meta::CPAN
use HTTP::Request::FromTemplate;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
# A request, snarfed from your network monitor logs:
my $template = <<TEMPLATE
POST http://[% host %][% path %][% query %] HTTP/1.1
Host: [% host %]
Connection: keep-alive
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
User-Agent: QuickTime (qtver=5.0.2;os=Windows NT 5.1)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Keep-Alive: 300
Referer: http://[% host %][% path %][% query %]
TEMPLATE
my $t = HTTP::Request::FromTemplate->new(template => $template);
lib/HTTP/Request/FromTemplate.pm view on Meta::CPAN
use HTTP::Request::FromTemplate;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
# A request, snarfed from your network monitor logs:
my $template = <<TEMPLATE
POST http://[% host %][% path %][% query %] HTTP/1.1
Host: [% host %]
Connection: keep-alive
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
User-Agent: QuickTime (qtver=5.0.2;os=Windows NT 5.1)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Keep-Alive: 300
Referer: http://[% host %][% path %][% query %]
TEMPLATE
my $t = HTTP::Request::FromTemplate->new(template => $template);
t/http_request_fromtemplate_03_content_length.t view on Meta::CPAN
use_ok "HTTP::Request::FromTemplate";
run \&template_identity;
__DATA__
=== Content-Length
--- template
POST http://[% host %][% path %][% query %] HTTP/1.1
Host: [% host %]
Connection: keep-alive
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Keep-Alive: 300
Referer: http://[% host %][% path %][% query %]
Content-Type: application/x-www-form-urlencoded
Content-Length: [% content_length %]
node_id=3628&op=message&message=[% message %]&message_send=talk
--- data eval
{
'host' => 'perlmonks.org',
'path' => '/',
'query' => '?',
message => 'Hello%20World',
}
--- expected
POST http://perlmonks.org/? HTTP/1.1
Connection: keep-alive
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
Host: perlmonks.org
Referer: http://perlmonks.org/?
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
Content-Length: 64
Content-Type: application/x-www-form-urlencoded
Keep-Alive: 300
( run in 2.144 seconds using v1.01-cache-2.11-cpan-71847e10f99 )