2023-05-24 21:21:00 +09:00
|
|
|
# curl
|
|
|
|
|
|
|
|
> データをサーバーから転送、もしくはサーバーへ転送します。
|
|
|
|
> HTTP、FTP、POP3を含むほとんどのプロトコルをサポートしています。
|
2025-01-16 20:31:06 +01:00
|
|
|
> もっと詳しく: <https://curl.se/docs/manpage.html>。
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- URLのコンテンツをファイルにダウンロードする:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{http://example.com}} {{[-o|--output]}} {{ファイルパス}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- ファイルをダウンロードし、URLにより指定されたファイル名で出力を保存する:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-O|--remote-name]}} {{http://example.com/filename}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- ファイルをダウンロードし、ロケーションレスポンスヘッダーのリダイレクトに追従しつつ自動的に以前のファイル転送を継続(再開)する。サーバーエラー時にはエラーを返す:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-f|--fail]}} {{[-O|--remote-name]}} {{[-L|--location]}} {{[-C|--continue-at]}} - {{http://example.com/filename}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
2024-10-20 00:02:10 +02:00
|
|
|
- フォームエンコードされたデータを送信する(`application/x-www-form-urlencoded`型のPOSTリクエスト)。`stdin`(標準入力) から読み込むには、`--data @file_name` または `--data @'-'` を使用する:
|
2023-05-24 21:21:00 +09:00
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-d|--data]}} {{'name=bob'}} {{http://example.com/form}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- カスタムHTTPメソッドを用いて追加のヘッダーを持つリクエストを送信する:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-H|--header]}} {{'X-My-Header: 123'}} {{[-X|--request]}} {{PUT}} {{http://example.com}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- 適切なContent-Type 表現ヘッダーを指定することで、JSONフォーマットでデータを送信する:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-d|--data]}} {{'{"name":"bob"}'}} {{[-H|--header]}} {{'Content-Type: application/json'}} {{http://example.com/users/1234}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- サーバー認証のためユーザー名とパスワードを送る:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-u|--user]}} {{ユーザー名}} {{http://example.com}}`
|
2023-05-24 21:21:00 +09:00
|
|
|
|
|
|
|
- リソースのクライアント証明書とキーを送り、証明書の検証をスキップする:
|
|
|
|
|
2025-03-19 00:36:34 +02:00
|
|
|
`curl {{[-E|--cert]}} {{client.pem}} --key {{key.pem}} {{[-k|--insecure]}} {{https://example.com}}`
|