=encoding euc-jp =head1 NAME =begin original HTTP::Request::Common - Construct common HTTP::Request objects =end original HTTP::Request::Common - 汎用のHTTP::Request オブジェクトの組み立て =head1 SYNOPSIS use HTTP::Request::Common; $ua = LWP::UserAgent->new; $ua->request(GET 'http://www.sn.no/'); $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]); =head1 DESCRIPTION =begin original This module provide functions that return newly created C objects. These functions are usually more convenient to use than the standard C constructor for the most common requests. The following functions are provided: =end original このモジュールは新しく作成された C オブジェクトを 返す関数を提供します。 これらの関数はこれらの一般的なリクエストのための標準の C コンストラクタよりも、通常より使いやすいものです。 以下の関数が提供されます: =over 4 =item GET $url =item GET $url, Header => Value,... =begin original The GET() function returns an C object initialized with the "GET" method and the specified URL. It is roughly equivalent to the following call =end original GET() 関数は GET メソッドと指定された URL で初期化された C オブジェクトを返します。 それはおおざっぱには以下の呼び出しと同じです: HTTP::Request->new( GET => $url, HTTP::Headers->new(Header => Value,...), ) =begin original but is less cluttered. What is different is that a header named C will initialize the content part of the request instead of setting a header field. Note that GET requests should normally not have a content, so this hack makes more sense for the PUT() and POST() functions described below. =end original しかし散らかりは少ないです。 違うところは、C という名前のヘッダはヘッダフィールドを 設定するのではなく、リクエストの内容として初期化されます。 GET リクエストは普通内容を持たないので、後述する PUT() メソッドと POST() メソッドをハックする方が理にかなっていることに注意してください。 =begin original The get(...) method of C exists as a shortcut for $ua->request(GET ...). =end original C の get(...) メソッドは、$ua->request(GET ...) への ショートカットとして存在しています。 =item HEAD $url =item HEAD $url, Header => Value,... =begin original Like GET() but the method in the request is "HEAD". =end original GET() と同様ですが、このメソッドのリクエストは "HEAD" です。 =begin original The head(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(HEAD ...). =end original C の head(...) メソッドは $ua->request(HEAD ...) への ショートカットとして存在しています。 =item PUT $url =item PUT $url, Header => Value,... =item PUT $url, Header => Value,..., Content => $content =begin original Like GET() but the method in the request is "PUT". =end original GET() と同様ですが、このメソッドのリクエストは "PUT" です。 =begin original The content of the request can be specified using the "Content" pseudo-header. This steals a bit of the header field namespace as there is no way to directly specify a header that is actually called "Content". If you really need this you must update the request returned in a separate statement. =end original このリクエストの内容は "Content" 疑似ヘッダを使って指定できます。 これはヘッダフィールド名前空間をほんの少し借用しているので、 本当に "Content" という名前のヘッダを直接指定する方法はありません。 これが本当に必要なら、別々の文で返されたリクエストを 更新しなければなりません。 =item POST $url =item POST $url, Header => Value,... =item POST $url, $form_ref, Header => Value,... =item POST $url, Header => Value,..., Content => $form_ref =item POST $url, Header => Value,..., Content => $content =begin original This works mostly like PUT() with "POST" as the method, but this function also takes a second optional array or hash reference parameter $form_ref. As for PUT() the content can also be specified directly using the "Content" pseudo-header, and you may also provide the $form_ref this way. =end original これは "POST" をメソッドとしてほとんど PUT() のように機能します。 しかしこの関数は 2 番目のオプションの配列またはハッシュリファレンスの パラメータ $form_ref を取ります。 PUT() では "Content" 疑似ヘッダを使って直接指定することもできますが、 この方法で $form_ref を提供することもできます。 =begin original The $form_ref argument can be used to pass key/value pairs for the form content. By default we will initialize a request using the C content type. This means that you can emulate a HTML Eform> POSTing like this: =end original $form_ref 引数はフォームコンテントのためのキー/値の組を渡すために 使うことが出来ます。 デフォルトでは C コンテントタイプを 使ってリクエストを初期化します。 つまり以下のようにして HTML Eform> POSTすることを エミュレートできます: POST 'http://www.perl.org/survey.cgi', [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', perc => '3%', ]; =begin original This will create a HTTP::Request object that looks like this: =end original これは以下のような HTTP::Request オブジェクトを作成します: POST http://www.perl.org/survey.cgi Content-Length: 66 Content-Type: application/x-www-form-urlencoded name=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25 =begin original Multivalued form fields can be specified by either repeating the field name or by passing the value as an array reference. =end original 複数の値を持つフォームフィールドは、フィールド名を繰り返すか、 配列リファレンスを渡すことで指定できます。 =begin original The POST method also supports the C content used for I as specified in RFC 1867. You trigger this content format by specifying a content type of C<'form-data'> 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: =end original POST メソッドはRFC1867 で示された Form-based File Upload のために使われる C コンテントもサポートします。 リクエストヘッダの一つとして C<'form-data'> のコンテントタイプを 指定することにより、このコンテントフォーマットを利用することが出来ます。 もし $form_ref の中の値の1つが配列リファレンスであれば、それは以下の解釈で ファイル部分の指定であるように扱われます: [ $file, $filename, Header => Value... ] [ undef, $filename, Header => Value,..., Content => $content ] =begin original 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 C as $file value if you want to specify the content directly with a C header. 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 want to suppress sending the filename when you provide a $file value. =end original 配列での先頭の値 ($file) はオープンするファイルの名前です。 このファイルは読みこまれ、その内容がリクエストに入れられます。 もしファイルをオープンできなければルーチンは croak します。 コンテントを直接 C ヘッダで指定したければ $file の値を C に してください。 $filename はリクエストで報告されるファイル名です。 この値が未定義であれば、$file の基本名が使われます。 $file の値を提供したとき、ファイル名の送信をよくせいしたいなら、 $filename に空文字列を指定することができます。 =begin original If a $file is provided by no C header, then C and C will be filled in automatically with the values returned by LWP::MediaTypes::guess_media_type() =end original C なしで $file が提供された場合、C と C は LWP::MediaTypes::guess_media_type() の 返り値を使って自動的に埋められます。 =begin original Sending my F<~/.profile> to the survey used as example above can be achieved by this: =end original 上記の例として F<~/.profile> を survey に送信することが以下のようにして 実現できます: POST 'http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Gisle Aas', email => 'gisle@aas.no', gender => 'M', born => '1964', init => ["$ENV{HOME}/.profile"], ] =begin original This will create a HTTP::Request object that almost looks this (the boundary and the content of your F<~/.profile> is likely to be different): =end original これはおおむね以下のような HTTP::Request オブジェクトを作成します (バウンダリと F<~/.profile> の中身は違っていることでしょう): POST http://www.perl.org/survey.cgi Content-Length: 388 Content-Type: multipart/form-data; boundary="6G+f" --6G+f Content-Disposition: form-data; name="name" Gisle Aas --6G+f Content-Disposition: form-data; name="email" gisle@aas.no --6G+f Content-Disposition: form-data; name="gender" M --6G+f Content-Disposition: form-data; name="born" 1964 --6G+f Content-Disposition: form-data; name="init"; filename=".profile" Content-Type: text/plain PATH=/local/perl/bin:$PATH export PATH --6G+f-- =begin original 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 F if you wish; however, if the file is not a plain file, there will be no Content-Length header defined for the request. Not all servers (or server applications) like this. Also, if the file(s) change in size between the time the Content-Length is calculated and the time that the last chunk is delivered, the subroutine will C. =end original (エクスポート可能な) $DYNAMIC_FILE 変数を TRUE に設定すると、content 属性として サブルーチンクロージャでリクエストオブジェクトを取得します。 このサブルーチンは命令のなかのすべてのファイルの内容を読みこみ、それを 適切なチャンクにいれて返します。 これにより大量のメモリを使わずに任意の大きなファイルを アップロードすることができます。 お望みであれば F のような無限大のファイルを アップロードすることすら可能です; しかし、ファイルが普通のファイルでない場合、 リクエストのために定義された Content-Length ヘッダがありません。 すべてのサーバ(またはサーバアプリケーション)が そのようであるというわけではありません。 また、Content-Length が計算された時点と最後のチャンクを受け取った時点で ファイルサイズが異なる場合、サブルーチンは C します。 =begin original The post(...) method of "LWP::UserAgent" exists as a shortcut for $ua->request(POST ...). =end original "LWP::UserAgent" の post(...) メソッドは $ua->request(POST ...) への ショートカットとして存在しています。 =back =head1 SEE ALSO L, L =head1 COPYRIGHT Copyright 1997-2004, Gisle Aas This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =begin meta Translated: Hippo2000 (5.48) Updated: Kentaro SHIRAKATA (5.813) =end meta =cut