我想使用該curl
命令發送一個發布請求,其中包含執行腳本或命令產生的資料,在這種情況下,命令是ifconfig
. 我正在尋找可以在 Linux 終端或 Windows CMD 中執行的 oneliner。
簡而言之,我想將命令的結果發送到服務器。
uj5u.com熱心網友回復:
將資料通過管道傳輸到curl
的標準輸入,并用于-d @/-
告訴 curl 從標準輸入中讀取資料。
命令列實用程式通常用于-
表示標準輸入。Curl 就是這樣一種實用程式。
在 curl 中,-d @something
將期望從 path 獲取其資料something
。
所以-d @-
告訴curl
從標準輸入中獲取它的 POST 資料。
然后,您可以將要上傳的資料直接通過管道傳輸到curl
:
% echo "I am command output" | curl https://httpbin.org/anything -X POST -d @-
{
"args": {},
"data": "",
"files": {},
"form": {
"I am command output": ""
},
"headers": {
"Accept": "*/*",
"Content-Length": "19",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.79.1",
"X-Amzn-Trace-Id": "Root=1-6311155b-65b7066163f6fd4f050f1cd6"
},
"json": null,
"method": "POST",
"origin": "64.188.162.105",
"url": "https://httpbin.org/anything"
}
uj5u.com熱心網友回復:
這個命令對我有用
curl -X POST -d "$(any command here)" https://XXXX.XXX
,但它僅適用于 UNIX 或 Linux,不適用于 Windows CMD 或 PowerShell。如果您知道如何使其適用于 CMD 和 PS,請發表評論。
uj5u.com熱心網友回復:
curl -X POST url
-H 'Content-Type: text/plain'
-d 'Your Response'
如果 url 是 PHP 腳本,那么獲取資料的腳本就是:
$command = file_get_contents('php://input');
exec($command);
Content-Type 是將 -d 資料放入請求正文中的內容。
或者你可以使用表單資料
curl -X POST url
-d 'response=Your Response'
PHP腳本將是
$command = $_POST['response'];
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/507064.html