home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>HTTP::Request::Common - Construct common HTTP::Request objects</TITLE>
- <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> HTTP::Request::Common - Construct common HTTP::Request objects</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>HTTP::Request::Common - Construct common HTTP::Request objects</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use HTTP::Request::Common;
- $ua = LWP::UserAgent->new;
- $ua->request(GET '<A HREF="http://www.sn.no/">http://www.sn.no/</A>');
- $ua->request(POST '<A HREF="http://somewhere/foo">http://somewhere/foo</A>', [foo => bar, bar => foo]);</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This module provide functions that return newly created HTTP::Request
- objects. These functions are usually more convenient to use than the
- standard HTTP::Request constructor for these common requests. The
- following functions are provided.</P>
- <DL>
- <DT><STRONG><A NAME="item_GET_%24url%2C_Header_%3D%3E_Value%2C%2E%2E%2E">GET $url, Header => Value,...</A></STRONG><BR>
- <DD>
- The <CODE>GET()</CODE> function returns a HTTP::Request object initialized with the
- GET method and the specified URL. Without additional arguments it
- is exactly equivalent to the following call
- <PRE>
- HTTP::Request->new(GET => $url)</PRE>
- <P>but is less cluttered. It also reads better when used together with the
- LWP::UserAgent-><CODE>request()</CODE> method:</P>
- <PRE>
- my $ua = new LWP::UserAgent;
- my $res = $ua->request(GET '<A HREF="http://www.sn.no">http://www.sn.no</A>')
- if ($res->is_success) { ...</PRE>
- <P>You can also initialize header values in the request by specifying
- some key/value pairs as optional arguments. For instance:</P>
- <PRE>
- $ua->request(GET '<A HREF="http://www.sn.no">http://www.sn.no</A>',
- If_Match => 'foo',
- From => 'gisle@aas.no',
- );</PRE>
- <P>A header key called 'Content' is special and when seen the value will
- initialize the content part of the request instead of setting a header.</P>
- <P></P>
- <DT><STRONG><A NAME="item_HEAD_%24url%2C_%5BHeader_%3D%3E_Value%2C%2E%2E%2E%">HEAD $url, [Header => Value,...]</A></STRONG><BR>
- <DD>
- Like <CODE>GET()</CODE> but the method in the request is HEAD.
- <P></P>
- <DT><STRONG><A NAME="item_PUT_%24url%2C_%5BHeader_%3D%3E_Value%2C%2E%2E%2E%5">PUT $url, [Header => Value,...]</A></STRONG><BR>
- <DD>
- Like <CODE>GET()</CODE> but the method in the request is PUT.
- <P></P>
- <DT><STRONG><A NAME="item_POST_%24url%2C_%5B%24form_ref%5D%2C_%5BHeader_%3D%">POST $url, [$form_ref], [Header => Value,...]</A></STRONG><BR>
- <DD>
- This works mostly like <CODE>GET()</CODE> with POST as the method, but this function
- also takes a second optional array or hash reference parameter
- ($form_ref). This argument can be used to pass key/value pairs for
- the form content. By default we will initialize a request using the
- <CODE>application/x-www-form-urlencoded</CODE> content type. This means that
- you can emulate a HTML <form> POSTing like this:
- <PRE>
- POST '<A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>',
- [ name => 'Gisle Aas',
- email => 'gisle@aas.no',
- gender => 'M',
- born => '1964',
- perc => '3%',
- ];</PRE>
- <P>This will create a HTTP::Request object that looks like this:</P>
- <PRE>
- POST <A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>
- Content-Length: 66
- Content-Type: application/x-www-form-urlencoded</PRE>
- <PRE>
- name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25</PRE>
- <P>The POST method also supports the <CODE>multipart/form-data</CODE> content used
- for <EM>Form-based File Upload</EM> as specified in RFC 1867. You trigger
- this content format by specifying a content type of <CODE>'form-data'</CODE> as
- one of the request headers. If one of the values in the $form_ref is
- an array reference, then it is treated as a file part specification
- with the following interpretation:</P>
- <PRE>
- [ $file, $filename, Header => Value... ]</PRE>
- <P>The first value in the array ($file) is the name of a file to open.
- This file will be read and its content placed in the request. The
- routine will croak if the file can't be opened. Use an <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> as $file
- value if you want to specify the content directly. The $filename is
- the filename to report in the request. If this value is undefined,
- then the basename of the $file will be used. You can specify an empty
- string as $filename if you don't want any filename in the request.</P>
- <P>Sending my <EM>~/.profile</EM> to the survey used as example above can be
- achieved by this:</P>
- <PRE>
- POST '<A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>',
- Content_Type => 'form-data',
- Content => [ name => 'Gisle Aas',
- email => 'gisle@aas.no',
- gender => 'M',
- born => '1964',
- init => ["$ENV{HOME}/.profile"],
- ]</PRE>
- <P>This will create a HTTP::Request object that almost looks this (the
- boundary and the content of your <EM>~/.profile</EM> is likely to be
- different):</P>
- <PRE>
- POST <A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>
- Content-Length: 388
- Content-Type: multipart/form-data; boundary="6G+f"</PRE>
- <PRE>
- --6G+f
- Content-Disposition: form-data; name="name"
- </PRE>
- <PRE>
-
- Gisle Aas
- --6G+f
- Content-Disposition: form-data; name="email"</PRE>
- <PRE>
-
- gisle@aas.no
- --6G+f
- Content-Disposition: form-data; name="gender"</PRE>
- <PRE>
-
- M
- --6G+f
- Content-Disposition: form-data; name="born"</PRE>
- <PRE>
-
- 1964
- --6G+f
- Content-Disposition: form-data; name="init"; filename=".profile"
- Content-Type: text/plain</PRE>
- <PRE>
-
- PATH=/local/perl/bin:$PATH
- export PATH</PRE>
- <PRE>
- --6G+f--</PRE>
- <P>If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE
- value, then you get back a request object with a subroutine closure as
- the content attribute. This subroutine will read the content of any
- files on demand and return it in suitable chunks. This allow you to
- upload arbitrary big files without using lots of memory. You can even
- upload infinite files like <EM>/dev/audio</EM> if you wish. Another
- difference is that there will be no Content-Length header defined for
- the request if you use this feature. Not all servers (or server
- applications) like this.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../../site/lib/HTTP/Request.html">the HTTP::Request manpage</A>, <A HREF="../../../../site/lib/LWP/UserAgent.html">the LWP::UserAgent manpage</A></P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright 1997-1998, Gisle Aas</P>
- <P>This library is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> HTTP::Request::Common - Construct common HTTP::Request objects</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-