コンテンツにスキップ

curl

ファイルをダウンロードする

1
2
3
4
5
# filenameとしてファイルを保存する
$ curl -fsSL https://path/to/file -o filename

# デフォルトのファイル名で保存する
$ curl -fsOSL https://path/to/file
オプション 説明
-f サーバーエラーが起きたときの HTML を出力しない。
-s ダウンロードの進捗を表示しない。
-S エラーメッセージを表示しない。
-L リダイレクトが発生したときそちらへリクエストし直す。
-o ${filename} ファイル名を指定して保存する。

HTTP リクエストする

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# GET
$ curl http://localhost/api
$ curl -X GET http://localhost/api

# GET(リクエストヘッダーあり)
$ curl -X GET -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" http://localhost/api

# POST(リクエストヘッダーあり)
$ curl -X POST http://localhost/api

# POST(リクエストボディあり)
$ curl -X POST -H "Content-Type: application/json" -d '{"test": 1}' http://localhost/api

# POST(リクエストヘッダーあり、リクエストボディあり)
$ curl -X POST -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -d '{"test": 1}' http://localhost/api