如何在此脚本末尾包含 POST 请求数据及其各自的 url?

How do I include POST request data with their respective url at the end of this script?

test_url() {
  local status=$(curl -o /dev/null -s -w "%{http_code}\n" -H "Authorization: token abc123" -H "Content-Type: application/json" --request POST -d '{"abc":"123", "xyz":"456"}' "")

  if [ "$status" = 200 ]; then
    echo " is running successfully"
  else
    echo "Error at . Status code: $status"
  fi
}

test_url https://url_1.com url_1
test_url https://url_2.com url_2

上面的脚本只是打印 url_1 is 运行 successfully or Error at url_2。状态码:401,取决于状态码。

假设“abc”:“123”是 url_1 的 POST 请求数据和 url_2 的“xyz”:“456”。同样,可能有很多数据,将它们全部放在一行中会造成混淆。所以我想将数据移动到它们各自的末尾 url 。类似于:

test_url '{"abc":"123"}' https://url_1.com url_1
test_url '{"xyz":"456"}' https://url_2.com url_2

我知道这是一种错误的格式,只是想举个例子。那么正确的做法是什么?

你可以试试这个:

local status=$(curl -o /dev/null -s -w "%{http_code}\n" -H "Authorization: token abc123" -H "Content-Type: application/json" -d "" -X POST )

致电:

test_url '{"abc":"123"}' "https://url_1.com"