簡體   English   中英

如何從用 bash 編寫的 CGI 腳本中獲取 POST 參數?

[英]How to get POST parameters from CGI scripts written in bash?

我正在使用用 bash 編寫的 CGI 腳本編寫 Web 應用程序。

對於GET請求,請求參數在名為$QUERY_STRING的變量中可用。 但是,我無法弄清楚POST請求的相似值將存儲在哪里。

我正在使用以下腳本:

#!"c:/msys64/usr/bin/bash.exe"
# On *nix, replace above with #!/bin/bash

echo -en "Status: 200 OK\r\n"
echo -en "Content-type: text/plain\r\n\r\n"

declare -x
declare -a

這就是我得到的:

$ curl -so - --data "abc=ZZZZZZ&d=PPPPPPPP" http://localhost/cgi-bin/test.sh | grep ZZZZZZ

$ curl -so - "http://localhost/cgi-bin/test.sh?abc=ZZZZZZ&d=PPPPPPPP" | grep ZZZZZZ
declare -x QUERY_STRING="abc=ZZZZZZ&d=PPPPPPPP"
declare -x REQUEST_URI="/cgi-bin/test.sh?abc=ZZZZZZ&d=PPPPPPPP"

如何檢索通過POST請求發送的值?

(如果重要的話,我使用的是 Apache 2.4)。

使用 POST 方法時。 POST 值將作為 CGI 程序的輸入。 所以在 bash 中只需使用

read POST_STRING

POST_STRING 然后包含與 QUERY_STRING 保存 GET 請求的值相同格式的 POST 值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM