如何从以bash编写的CGI脚本中获取POST参数? [英] How to get POST parameters from CGI scripts written in bash?

查看:607
本文介绍了如何从以bash编写的CGI脚本中获取POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆