home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _0a6ef51ea5bd2e1e19a608a0cd9dce99 < prev    next >
Encoding:
Text File  |  2000-03-23  |  8.2 KB  |  204 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>HTTP::Request::Common - Construct common HTTP::Request objects</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> HTTP::Request::Common - Construct common HTTP::Request objects</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  26.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  27. </UL>
  28. <!-- INDEX END -->
  29.  
  30. <HR>
  31. <P>
  32. <H1><A NAME="name">NAME</A></H1>
  33. <P>HTTP::Request::Common - Construct common HTTP::Request objects</P>
  34. <P>
  35. <HR>
  36. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  37. <UL>
  38. <LI>Linux</LI>
  39. <LI>Solaris</LI>
  40. <LI>Windows</LI>
  41. </UL>
  42. <HR>
  43. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  44. <PRE>
  45.   use HTTP::Request::Common;
  46.   $ua = LWP::UserAgent->new;
  47.   $ua->request(GET '<A HREF="http://www.sn.no/">http://www.sn.no/</A>');
  48.   $ua->request(POST '<A HREF="http://somewhere/foo">http://somewhere/foo</A>', [foo => bar, bar => foo]);</PRE>
  49. <P>
  50. <HR>
  51. <H1><A NAME="description">DESCRIPTION</A></H1>
  52. <P>This module provide functions that return newly created HTTP::Request
  53. objects.  These functions are usually more convenient to use than the
  54. standard HTTP::Request constructor for these common requests.  The
  55. following functions are provided.</P>
  56. <DL>
  57. <DT><STRONG><A NAME="item_GET_%24url%2C_Header_%3D%3E_Value%2C%2E%2E%2E">GET $url, Header => Value,...</A></STRONG><BR>
  58. <DD>
  59. The <CODE>GET()</CODE> function returns a HTTP::Request object initialized with the
  60. GET method and the specified URL.  Without additional arguments it
  61. is exactly equivalent to the following call
  62. <PRE>
  63.   HTTP::Request->new(GET => $url)</PRE>
  64. <P>but is less cluttered.  It also reads better when used together with the
  65. LWP::UserAgent-><CODE>request()</CODE> method:</P>
  66. <PRE>
  67.   my $ua = new LWP::UserAgent;
  68.   my $res = $ua->request(GET '<A HREF="http://www.sn.no">http://www.sn.no</A>')
  69.   if ($res->is_success) { ...</PRE>
  70. <P>You can also initialize header values in the request by specifying
  71. some key/value pairs as optional arguments.  For instance:</P>
  72. <PRE>
  73.   $ua->request(GET '<A HREF="http://www.sn.no">http://www.sn.no</A>',
  74.                    If_Match => 'foo',
  75.                    From     => 'gisle@aas.no',
  76.               );</PRE>
  77. <P>A header key called 'Content' is special and when seen the value will
  78. initialize the content part of the request instead of setting a header.</P>
  79. <P></P>
  80. <DT><STRONG><A NAME="item_HEAD_%24url%2C_%5BHeader_%3D%3E_Value%2C%2E%2E%2E%">HEAD $url, [Header => Value,...]</A></STRONG><BR>
  81. <DD>
  82. Like <CODE>GET()</CODE> but the method in the request is HEAD.
  83. <P></P>
  84. <DT><STRONG><A NAME="item_PUT_%24url%2C_%5BHeader_%3D%3E_Value%2C%2E%2E%2E%5">PUT $url, [Header => Value,...]</A></STRONG><BR>
  85. <DD>
  86. Like <CODE>GET()</CODE> but the method in the request is PUT.
  87. <P></P>
  88. <DT><STRONG><A NAME="item_POST_%24url%2C_%5B%24form_ref%5D%2C_%5BHeader_%3D%">POST $url, [$form_ref], [Header => Value,...]</A></STRONG><BR>
  89. <DD>
  90. This works mostly like <CODE>GET()</CODE> with POST as the method, but this function
  91. also takes a second optional array or hash reference parameter
  92. ($form_ref).  This argument can be used to pass key/value pairs for
  93. the form content.  By default we will initialize a request using the
  94. <CODE>application/x-www-form-urlencoded</CODE> content type.  This means that
  95. you can emulate a HTML <form> POSTing like this:
  96. <PRE>
  97.   POST '<A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>',
  98.        [ name   => 'Gisle Aas',
  99.          email  => 'gisle@aas.no',
  100.          gender => 'M',
  101.          born   => '1964',
  102.          perc   => '3%',
  103.        ];</PRE>
  104. <P>This will create a HTTP::Request object that looks like this:</P>
  105. <PRE>
  106.   POST <A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>
  107.   Content-Length: 66
  108.   Content-Type: application/x-www-form-urlencoded</PRE>
  109. <PRE>
  110.   name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25</PRE>
  111. <P>The POST method also supports the <CODE>multipart/form-data</CODE> content used
  112. for <EM>Form-based File Upload</EM> as specified in RFC 1867.  You trigger
  113. this content format by specifying a content type of <CODE>'form-data'</CODE> as
  114. one of the request headers.  If one of the values in the $form_ref is
  115. an array reference, then it is treated as a file part specification
  116. with the following interpretation:</P>
  117. <PRE>
  118.   [ $file, $filename, Header => Value... ]</PRE>
  119. <P>The first value in the array ($file) is the name of a file to open.
  120. This file will be read and its content placed in the request.  The
  121. 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
  122. value if you want to specify the content directly.  The $filename is
  123. the filename to report in the request.  If this value is undefined,
  124. then the basename of the $file will be used.  You can specify an empty
  125. string as $filename if you don't want any filename in the request.</P>
  126. <P>Sending my <EM>~/.profile</EM> to the survey used as example above can be
  127. achieved by this:</P>
  128. <PRE>
  129.   POST '<A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>',
  130.        Content_Type => 'form-data',
  131.        Content      => [ name  => 'Gisle Aas',
  132.                          email => 'gisle@aas.no',
  133.                          gender => 'M',
  134.                          born   => '1964',
  135.                          init   => ["$ENV{HOME}/.profile"],
  136.                        ]</PRE>
  137. <P>This will create a HTTP::Request object that almost looks this (the
  138. boundary and the content of your <EM>~/.profile</EM> is likely to be
  139. different):</P>
  140. <PRE>
  141.   POST <A HREF="http://www.perl.org/survey.cgi">http://www.perl.org/survey.cgi</A>
  142.   Content-Length: 388
  143.   Content-Type: multipart/form-data; boundary="6G+f"</PRE>
  144. <PRE>
  145.   --6G+f
  146.   Content-Disposition: form-data; name="name"
  147. </PRE>
  148. <PRE>
  149.  
  150.   Gisle Aas
  151.   --6G+f
  152.   Content-Disposition: form-data; name="email"</PRE>
  153. <PRE>
  154.  
  155.   gisle@aas.no
  156.   --6G+f
  157.   Content-Disposition: form-data; name="gender"</PRE>
  158. <PRE>
  159.  
  160.   M
  161.   --6G+f
  162.   Content-Disposition: form-data; name="born"</PRE>
  163. <PRE>
  164.  
  165.   1964
  166.   --6G+f
  167.   Content-Disposition: form-data; name="init"; filename=".profile"
  168.   Content-Type: text/plain</PRE>
  169. <PRE>
  170.  
  171.   PATH=/local/perl/bin:$PATH
  172.   export PATH</PRE>
  173. <PRE>
  174.   --6G+f--</PRE>
  175. <P>If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE
  176. value, then you get back a request object with a subroutine closure as
  177. the content attribute.  This subroutine will read the content of any
  178. files on demand and return it in suitable chunks.  This allow you to
  179. upload arbitrary big files without using lots of memory.  You can even
  180. upload infinite files like <EM>/dev/audio</EM> if you wish.  Another
  181. difference is that there will be no Content-Length header defined for
  182. the request if you use this feature.  Not all servers (or server
  183. applications) like this.</P>
  184. <P></P></DL>
  185. <P>
  186. <HR>
  187. <H1><A NAME="see also">SEE ALSO</A></H1>
  188. <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>
  189. <P>
  190. <HR>
  191. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  192. <P>Copyright 1997-1998, Gisle Aas</P>
  193. <P>This library is free software; you can redistribute it and/or
  194. modify it under the same terms as Perl itself.</P>
  195. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  196. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  197. <STRONG><P CLASS=block> HTTP::Request::Common - Construct common HTTP::Request objects</P></STRONG>
  198. </TD></TR>
  199. </TABLE>
  200.  
  201. </BODY>
  202.  
  203. </HTML>
  204.