3
# $Id: lwp-request,v 2.1 2002/01/03 02:07:02 gisle Exp $
3
# $Id: lwp-request,v 2.6 2003/10/26 14:39:18 gisle Exp $
5
5
# Simple user agent using LWP library.
9
lwp-request, GET, HEAD, POST - Simple WWW user agent
9
lwp-request - Simple command line user agent
54
Set the If-Modified-Since header in the request. If I<time> it the
54
Set the If-Modified-Since header in the request. If I<time> is the
55
55
name of a file, use the modification timestamp for this file. If
56
56
I<time> is not a file, it is parsed as a literal date. Take a look at
57
L<HTTP::Date> for recogniced formats.
57
L<HTTP::Date> for recognized formats.
59
59
=item -c <content-type>
178
178
$progname =~ s,.*[\\/],,; # use basename only
179
179
$progname =~ s/\.\w*$//; # strip extension, if any
181
$VERSION = sprintf("%d.%02d", q$Revision: 2.1 $ =~ /(\d+)\.(\d+)/);
181
$VERSION = sprintf("%d.%02d", q$Revision: 2.6 $ =~ /(\d+)\.(\d+)/);
227
227
my($self, $realm, $uri) = @_;
228
228
if ($main::options{'C'}) {
229
229
return split(':', $main::options{'C'}, 2);
231
232
my $netloc = $uri->host_port;
232
233
print "Enter username for $realm at $netloc: ";
233
234
my $user = <STDIN>;
311
313
if ($options{'f'}) {
312
314
if ($options{'c'}) {
313
315
$allowed_methods{$method} = "C"; # force content
315
318
$allowed_methods{$method} = "";
317
} elsif (!defined $allowed_methods{$method}) {
321
elsif (!defined $allowed_methods{$method}) {
318
322
die "$progname: $method is not an allowed method\n";
354
359
$options{'c'} = ($method eq "POST") ?
355
360
"application/x-www-form-urlencoded"
358
364
die "$progname: Illegal Content-type format\n"
359
365
unless $options{'c'} =~ m,^[\w\-]+/[\w\-]+(?:\s*;.*)?$,
363
369
binmode STDIN unless -t or $options{'a'};
364
370
$content = join("", <STDIN>);
366
373
die "$progname: Can't set Content-type for $method requests\n"
367
374
if defined $options{'c'};
426
435
print "\n"; # separate headers and content
429
if ($response->is_success) {
430
unless ($options{'d'}) {
432
$response->content_type eq 'text/html') {
434
my $html = HTML::Parse::parse_html($response->content);
436
$options{'o'} eq 'ps' && do {
437
require HTML::FormatPS;
438
my $f = HTML::FormatPS->new;
439
print $f->format($html);
442
$options{'o'} eq 'text' && do {
443
require HTML::FormatText;
444
my $f = HTML::FormatText->new;
445
print $f->format($html);
448
$options{'o'} eq 'html' && do {
449
print $html->as_HTML;
452
$options{'o'} eq 'links' && do {
453
my $base = $response->base;
454
for ( @{ $html->extract_links } ) {
455
my($link, $elem) = @$_;
456
my $tag = uc $elem->tag;
457
$link = URI->new($link)->abs($base)->as_string;
458
print "$tag\t$link\n";
462
$options{'o'} eq 'dump' && do {
466
# It is bad to not notice this before now :-(
467
die "Illegal -o option value ($options{'o'})\n";
470
binmode STDOUT unless $options{'a'};
471
print $response->content;
438
unless ($options{'d'}) {
440
$response->content_type eq 'text/html') {
442
my $html = HTML::Parse::parse_html($response->content);
444
$options{'o'} eq 'ps' && do {
445
require HTML::FormatPS;
446
my $f = HTML::FormatPS->new;
447
print $f->format($html);
450
$options{'o'} eq 'text' && do {
451
require HTML::FormatText;
452
my $f = HTML::FormatText->new;
453
print $f->format($html);
456
$options{'o'} eq 'html' && do {
457
print $html->as_HTML;
460
$options{'o'} eq 'links' && do {
461
my $base = $response->base;
462
for ( @{ $html->extract_links } ) {
463
my($link, $elem) = @$_;
464
my $tag = uc $elem->tag;
465
$link = URI->new($link)->abs($base)->as_string;
466
print "$tag\t$link\n";
470
$options{'o'} eq 'dump' && do {
474
# It is bad to not notice this before now :-(
475
die "Illegal -o option value ($options{'o'})\n";
475
print STDERR $response->error_as_HTML unless $options{'d'};
479
binmode STDOUT unless $options{'a'};
480
print $response->content;
484
$errors++ unless $response->is_success;