2016年1月1日金曜日

curlでHTTPのステータス、ヘッダ、ボディを分割してファイルに保存

curlで任意のHTTPのステータス(レスポンス時間など)、ヘッダ、ボディを分割してファイルに保存する場合のメモ。

$ now=`date +"%Y%m%d%H%M%S"`
$ url="http://example.com"
$ file="test"

$ curl -s -v -w "{ \"time\":\"${now}\", \"response\" : %{time_total}, \"status_code\" : %{http_code}  }" \
-X POST \
"${url}" \
-o ${file}_body \
2> ${file}_header \
> ${file}_status