「CURL」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(新規作成(英語版より転載))
 
 
(2人の利用者による、間の15版が非表示)
1行目: 1行目:
 
{{Lowercase title}}
 
{{Lowercase title}}
  +
[[en:CURL]]
  +
[[ru:CURL]]
 
[[Category:ダウンロードユーティリティ]]
 
[[Category:ダウンロードユーティリティ]]
  +
[https://curl.haxx.se/ cURL] は URL を使ってデータを転送するためのコマンドラインツールおよびライブラリです。このコマンドは、[[HTTP]]、HTTPS、[[FTP]]、[[SCP]] や SFTP などさまざまなプロトコルをサポートしています。また、スクリプトのように、ユーザーの操作なしで動作するように設計されています。
[https://curl.haxx.se/ cURL] is a command line tool and library for transferring data with URLs. The command supports a number of different protocols, including [[HTTP]], HTTPS, [[FTP]], [[SCP]], and SFTP. It is also designed to work without user interaction, like in scripts.
 
   
  +
{{Note|表面的には wget と同等ですが、違う部分もあります、こちらを参照してください。[https://curl.se/docs/faq.html#Can_I_do_recursive_fetches_with 再帰的フェッチを実行できますか?]、[https://superuser.com/a/972282 指定された wget コマンドと同等の curl コマンドを実行できますか?] [https://curl.se/docs/faq.html#What_is_curl_not curl には無いもの]}}
== Installation ==
 
   
  +
== インストール ==
[[Install]] the {{Pkg|curl}} package.
 
   
  +
{{Pkg|curl}} パッケージを[[インストール]]します。
== Usage ==
 
   
=== Downloading ===
+
== 使用方法 ==
   
  +
=== ダウンロード ===
A common use case for cURL is to download the resource to a specified file:
 
   
  +
cURL の一般的な使用例は、指定したファイルにリソースをダウンロードすることです:
$ curl -o ''file name'' ''URL''
 
   
  +
$ curl --output ''file name'' ''URL''
If the URL contains the file name, you can save the resource directly to a file of that name:
 
   
  +
URL にファイル名が含まれている場合は、リソースをその名前のファイルに直接保存できます:
$ curl -O ''URL''
 
   
  +
$ curl --remote-name ''URL''
Similarly, you can use {{ic|-J}} to accept a hint from an HTTP server (from the {{ic|Content-Disposition}} header) for what the file should be named. If combined with {{ic|-O}}, curl will use the file name specified by the URL if the HTTP server does not return a file name hint in its response.
 
   
  +
同様に、{{ic|-J}} を使用すると、ファイルの名前を決めるためのヒントを HTTP サーバー ({{ic|Content-Disposition}} ヘッダー) から受け取ることができます。{{ic|-O}} と組み合わせると、HTTP サーバーが応答でファイル名のヒントを返さなかった場合は、curl は URL で指定されたファイル名を使用します。
Alternatively you can print the resource to stdout by omitting the output options:
 
  +
  +
また、出力オプションを省略して、リソースを標準出力に出力することもできます:
   
 
$ curl ''URL''
 
$ curl ''URL''
27行目: 31行目:
 
=== HTTP POST ===
 
=== HTTP POST ===
   
  +
cURL を使用して HTTP POST リクエストを行うことができます。
You can use cURL to make HTTP POST requests:
 
   
 
$ curl -d ''<nowiki>'request body'</nowiki>'' ''URL''
 
$ curl -d ''<nowiki>'request body'</nowiki>'' ''URL''
   
  +
リクエストの本文がコマンドラインに収まらない場合は、cURL はファイルからリクエストを読み込むことができます。
If the request body cannot fit on the command line, cURL can read it from a file:
 
   
 
$ curl -d @''file name'' ''URL''
 
$ curl -d @''file name'' ''URL''
   
Sometimes, you may need to specify a custom value for the {{ic|Content-Type}} header (cURL's default is {{ic|application/x-www-form-urlencoded}}). You can do this with {{ic|-H}}. For example, if you wanted to make a POST request with a JSON body:
+
場合によっては、{{ic|Content-Type}} ヘッダーにカスタム値を指定する必要があるかもしれません(cURL のデフォルト値は {{ic|application/x-www-form-urlencoded}})。これには {{ic|-H}} を使います。例えば、JSON body を利用して、POST リクエストを作成する場合は以下のようにします。
   
 
$ curl -d ''<nowiki>'json body'</nowiki>'' -H 'Content-Type: application/json' ''URL''
 
$ curl -d ''<nowiki>'json body'</nowiki>'' -H 'Content-Type: application/json' ''URL''
   
  +
なお、curl には json で投稿データを書き込み、それらのヘッダーを自動的に変更するオプションもあります: {{ic|--json}}:
== See also ==
 
  +
  +
$ curl --json '{"key":"value"}' ''URL''
   
  +
== ヒントとテクニック ==
* [[Wikipedia:cURL]]
 
  +
* [https://ec.haxx.se/ Everything curl] - Extensive guide to using cURL
 
  +
=== リダイレクトを追跡する ===
  +
  +
リダイレクト (HTTP から HTTPS へのリダイレクトなど) を追跡するには:
  +
  +
$ curl --location ''URL''
  +
  +
=== ダウンロードエラーを表示する ===
  +
  +
デフォルトでは、curl はエラーを無視します (たとえば、ファイルをダウンロードするときに、エラーが発生しても、curl は通知せず、空のファイルを作成します) エラーメッセージを表示させたい時は {{ic|--fail}} を使います:
  +
  +
$ curl --fail ''URL''
  +
  +
=== 圧縮 ===
  +
  +
データを [https://everything.curl.dev/usingcurl/downloads/compression 圧縮] して転送する場合 (たとえば、帯域幅が CPU よりも制限されている状況では、curl はデータを圧縮してダウンロードし、ダウンロード後に圧縮を解除します):
  +
  +
$ curl --compressed ''URL''
  +
  +
=== プログレスバー ===
  +
  +
curl には、ファイルをダウンロードするときに通常の ProgressBar を使用するオプションがあります (例:{{ic|[##### ] 80%}} )
  +
  +
$ curl --progress-bar ''URL''
  +
  +
=== globing ===
  +
  +
また、curl で [https://everything.curl.dev/cmdline/globbing globing] を使用することもできます。
  +
  +
$ curl "example.com/images/[1-9].png"
  +
$ curl "example.com/{first_page,second_page,third_page}"
  +
  +
== 設定ファイル ==
  +
  +
curl はホームディレクトリと {{ic|$XDG_CONFIG_HOME}} で {{ic|.curlrc}} という [https://everything.curl.dev/cmdline/configfile config file] を検索します。デフォルトの curl で使用したいコマンドライン引数を入力します。例:
  +
  +
{{hc|$HOME/.curlrc|2=
  +
# this is a comment, the next line would be the option for progressbar:
  +
-#
  +
# to make curl always compress:
  +
--compressed
  +
# or just
  +
compressed
  +
}}
  +
  +
== 参照 ==
  +
  +
* [[Wikipedia:ja:cURL]]
  +
* [https://ec.haxx.se/ Everything curl] - cURL の使用に関する広範なガイド
 
* {{man|1|curl}}
 
* {{man|1|curl}}
  +
  +
{{TranslationStatus|CURL|2024-03-28|691337}}

2024年3月28日 (木) 01:20時点における最新版

cURL は URL を使ってデータを転送するためのコマンドラインツールおよびライブラリです。このコマンドは、HTTP、HTTPS、FTPSCP や SFTP などさまざまなプロトコルをサポートしています。また、スクリプトのように、ユーザーの操作なしで動作するように設計されています。

ノート: 表面的には wget と同等ですが、違う部分もあります、こちらを参照してください。再帰的フェッチを実行できますか?指定された wget コマンドと同等の curl コマンドを実行できますか? curl には無いもの

インストール

curl パッケージをインストールします。

使用方法

ダウンロード

cURL の一般的な使用例は、指定したファイルにリソースをダウンロードすることです:

$ curl --output file name URL

URL にファイル名が含まれている場合は、リソースをその名前のファイルに直接保存できます:

$ curl --remote-name URL

同様に、-J を使用すると、ファイルの名前を決めるためのヒントを HTTP サーバー (Content-Disposition ヘッダー) から受け取ることができます。-O と組み合わせると、HTTP サーバーが応答でファイル名のヒントを返さなかった場合は、curl は URL で指定されたファイル名を使用します。

また、出力オプションを省略して、リソースを標準出力に出力することもできます:

$ curl URL

HTTP POST

cURL を使用して HTTP POST リクエストを行うことができます。

$ curl -d 'request body' URL

リクエストの本文がコマンドラインに収まらない場合は、cURL はファイルからリクエストを読み込むことができます。

$ curl -d @file name URL

場合によっては、Content-Type ヘッダーにカスタム値を指定する必要があるかもしれません(cURL のデフォルト値は application/x-www-form-urlencoded)。これには -H を使います。例えば、JSON body を利用して、POST リクエストを作成する場合は以下のようにします。

$ curl -d 'json body' -H 'Content-Type: application/json' URL

なお、curl には json で投稿データを書き込み、それらのヘッダーを自動的に変更するオプションもあります: --json:

$ curl --json '{"key":"value"}' URL

ヒントとテクニック

リダイレクトを追跡する

リダイレクト (HTTP から HTTPS へのリダイレクトなど) を追跡するには:

$ curl --location URL

ダウンロードエラーを表示する

デフォルトでは、curl はエラーを無視します (たとえば、ファイルをダウンロードするときに、エラーが発生しても、curl は通知せず、空のファイルを作成します) エラーメッセージを表示させたい時は --fail を使います:

$ curl --fail URL

圧縮

データを 圧縮 して転送する場合 (たとえば、帯域幅が CPU よりも制限されている状況では、curl はデータを圧縮してダウンロードし、ダウンロード後に圧縮を解除します):

$ curl --compressed URL

プログレスバー

curl には、ファイルをダウンロードするときに通常の ProgressBar を使用するオプションがあります (例:[##### ] 80% )

$ curl --progress-bar URL

globing

また、curl で globing を使用することもできます。

$ curl "example.com/images/[1-9].png"
$ curl "example.com/{first_page,second_page,third_page}"

設定ファイル

curl はホームディレクトリと $XDG_CONFIG_HOME.curlrc という config file を検索します。デフォルトの curl で使用したいコマンドライン引数を入力します。例:

$HOME/.curlrc
# this is a comment, the next line would be the option for progressbar:
-#
# to make curl always compress:
--compressed
# or just
compressed

参照

翻訳ステータス: このページは en:CURL の翻訳バージョンです。最後の翻訳日は 2024-03-28 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。