📄 request.pm
字号:
## $Id: Request.pm,v 1.1 1999/07/21 19:12:29 kraven Exp $package HTTP::Request;=head1 NAMEHTTP::Request - Class encapsulating HTTP Requests=head1 SYNOPSIS require HTTP::Request; $request = HTTP::Request->new(GET => 'http://www.oslonett.no/');=head1 DESCRIPTIONC<HTTP::Request> is a class encapsulating HTTP style requests,consisting of a request line, some headers, and some (potentially empty)content. Note that the LWP library also uses this HTTP style requestsfor non-HTTP protocols.Instances of this class are usually passed to the C<request()> methodof an C<LWP::UserAgent> object: $ua = LWP::UserAgent->new; $request = HTTP::Request->new(GET => 'http://www.oslonett.no/'); $response = $ua->request($request);C<HTTP::Request> is a subclass of C<HTTP::Message> and thereforeinherits its methods. The inherited methods often used are header(),push_header(), remove_header(), headers_as_string() and content().See L<HTTP::Message> for details.The following additional methods are available:=over 4=cutrequire HTTP::Message;@ISA = qw(HTTP::Message);$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);use URI::URL ();use strict;=item $r = HTTP::Request->new($method, $url, [$header, [$content]])Constructs a new C<HTTP::Request> object describing a request on theobject C<$url> using method C<$method>. The C<$url> argument can beeither a string, or a reference to a C<URI::URL> object. The $headerargument should be a reference to an C<HTTP::Headers> object.=cutsub new{ my($class, $method, $url, $header, $content) = @_; my $self = $class->SUPER::new($header, $content); $self->method($method); $self->url($url); $self;}sub clone{ my $self = shift; my $clone = bless $self->SUPER::clone, ref($self); $clone->method($self->method); $clone->url($self->url); $clone;}=item $r->method([$val])=item $r->url([$val])These methods provide public access to the member variables containingrespectively the method of the request and the URL object of therequest.If an argument is given the member variable is given that as its newvalue. If no argument is given the value is not touched. In eithercase the previous value is returned.The url() method accept both a reference to a URI::URL object and astring as its argument. If a string is given, then it should beparseable as an absolute URL.=cutsub method { shift->_elem('_method', @_); }sub url{ my $self = shift; my $old = $self->{'_url'}; if (@_) { my $url = shift; if (!defined $url) { # that's ok } elsif (ref $url) { $url = $url->abs; } else { $url = eval { URI::URL->new($url) }; } $self->{'_url'} = $url; } $old;}*uri = \&url; # this is the same for now=item $r->as_string()Method returning a textual representation of the request.Mainly useful for debugging purposes. It takes no arguments.=cutsub as_string{ my $self = shift; my @result; #push(@result, "---- $self -----"); my $req_line = $self->method || "[NO METHOD]"; my $url = $self->url; $url = (defined $url) ? $url->as_string : "[NO URL]"; $req_line .= " $url"; my $proto = $self->protocol; $req_line .= " $proto" if $proto; push(@result, $req_line); push(@result, $self->headers_as_string); my $content = $self->content; if (defined $content) { push(@result, $content); } #push(@result, ("-" x 40)); join("\n", @result, "");}1;=back=head1 SEE ALSOL<HTTP::Headers>, L<HTTP::Message>, L<HTTP::Request::Common>=head1 COPYRIGHTCopyright 1995-1998 Gisle Aas.This library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -