我想在這個請求中添加睡眠,以免一次有太多請求給服務器帶來壓力。我嘗試添加睡眠,但沒有得到預期的行為。感謝您的幫助。
xargs -I{} curl --location --request POST 'https://g.com' \
--header 'Authorization: Bearer cc' \
--header 'Content-Type: application/json' \
--data-raw '{
"c_ids": [
"{}"
]
}' '; sleep 5m' < ~/recent.txt
uj5u.com熱心網友回復:
將任意字串轉義為有效的 JSON 是jq.
如果您沒有特別的理由在回圈之外定義 curl 引數:
while IFS= read -r json; do
curl \
--location --request POST 'https://g.com' \
--header 'Authorization: Bearer cc' \
--header 'Content-Type: application/json' \
--data-raw "$json"
sleep 5m
done < <(jq -Rc '{"c_ids": [ . ]}' recent.txt)
...或者如果你這樣做:
curl_args=(
--location --request POST 'https://g.com' \
--header 'Authorization: Bearer cc' \
--header 'Content-Type: application/json' \
)
while IFS= read -r json; do
curl "${curl_args[@]}" --data-raw "$json"
sleep 5m
done < <(jq -Rc '{"c_ids": [ . ]}' recent.txt)
uj5u.com熱心網友回復:
將睡眠放在 xargs 中有點不穩定。我建議采用以下更可能提供所需結果的方法。
#!/bin/sh
siteCommon="--location --request POST 'https://g.com' \
--header 'Authorization: Bearer cc' \
--header 'Content-Type: application/json' "
while read -r line
do
eval curl ${siteCommon} --data-raw \'{ \"c_ids\": [ \"${line}\" ] }\'
sleep 5m
done < ~/recent.txt
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/524556.html
標籤:linux重击卷曲终端
上一篇:使用ProcessBuilder和承載令牌執行curl命令
下一篇:將URL卷曲到vb.net
