如何从以bash编写的CGI脚本中获取POST参数? [英] How to get POST parameters from CGI scripts written in bash?
问题描述
我正在使用bash编写的CGI脚本编写Web应用程序.
I'm writing a web application using CGI scripts written in bash.
对于GET
请求,请求参数在名为$QUERY_STRING
的变量中可用.但是,我无法弄清楚类似的值将存储在POST
请求中的位置.
For GET
requests, the request parameters are available in a variable named $QUERY_STRING
. However, I'm unable to figure out where the similar value would be stored for POST
requests.
我正在使用以下脚本:
#!"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
请求发送的值?
How can I retrieve the values sent over POST
requests?
(如果有关系,我正在使用Apache 2.4).
(If it matters, I'm using Apache 2.4).
推荐答案
使用POST方法时. POST值将作为CGI程序的输入.所以在bash中只需使用
When using the POST method. The POST values will be the input to your CGI program. So in bash just use
read POST_STRING
然后,POST_STRING包含POST值,格式与QUERY_STRING保留GET请求的值相同.
POST_STRING then contains the POST values in the same format as QUERY_STRING holds the values for a GET request.
这篇关于如何从以bash编写的CGI脚本中获取POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!