curlでレスポンスのHTTPステータスとbodyを取得する

curlで実行時のレスポンスHTTPステータスとBodyを取得したい

方法

/get_https-status_body.sh
BASH
#!/bin/bash

response=$(curl -w '\n%{http_code}' -sL --url https://szk302.dev)

echo "status: ${response: -3}"
echo "body: ${response:0:-3}"

結果

console
status: 200
body: <!doctype html><html lang=ja dir=auto><head><meta name=generator content="Hugo 0.80.0">...省略</html>
szk302

この記事の著者

記事一覧へ
記事を検索

タイトル・タグ・記事本文から検索できます。

例えばAWSTerraformPowerShellGit