linux shell cgi post,linux下shell处理cgi的方法--post get
web server獲取網頁上HTML的DOM對象信息發送來的信息,主要有get和post方法。
介紹原理的文章很多,但介紹實際應用到linux的shell中的文章很少。
1、get方法
①表單源碼如下,有幾個HTML對象作為傳值對象。
CGI Test
Text field
Radio button
1
2
3
②cgi get腳本,使用環境變量QUERY_STRING傳值。
#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "Sample CGI Output"
echo ""
echo ""
#echo "Environment variables"
#echo ""
env
#echo ""
#echo "========================================================="
#echo ""
#echo "Form variables :"
#echo ""
str=$QUERY_STRING
echo $str
# [ "${str%&}" = "$str" ] && str="$str&"
# pair=${str%%&*}
# var=${pair%=*}
# val=${pair#*=}
pair=${str##*&}
var=${pair%=*}
val=${pair#*=}
str=${str#*&}
echo "$pair"
echo "$var"
echo "$val"
echo "$str"
echo ""
#echo $val
if [ $val = "lighton" ];then
echo "select to open light"
fi
if [ $val = "lightoff" ];then
echo "select to close light"
fi
if [ $val = "rolling" ];then
echo "select to rolling light"
fi
echo ""
echo ""
echo ""
2、post方法
①表單源碼
CGI Test
Text field
Radio button
1
2
3
Some text
②post傳值時,使用環境變量CONTENT_LENGTH表示傳輸數據長度。
而實際內容需要從標準輸入設備接收,這里使用命令“read pos -n CONTENT_LENGTH”,注意,接收個數需做限制。
#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "Sample CGI Output"
echo ""
echo ""
echo "Environment variables"
echo ""
env
echo ""
echo "========================================================="
echo ""
echo "Form variables :"
echo ""
#echo $CONTENT_LENGTH
read pos -n CONTENT_LENGTH
#echo $pos
tmp=${pos%%&*}
#echo $tmp
tmp=${tmp#*=}
echo "Text_Field=$tmp"
tmpcur=${pos#*&}
#echo $tmpcur
tmp=${tmpcur%%&*}
tmp=${tmp#*=}
echo "Radio_Button=$tmp"
tmpcur=${tmpcur#*&}
tmp=${tmpcur%%&*}
tmp=${tmp#*=}
echo "Text_Area=$tmp"
echo ""
echo ""
本文參考http://blog.chinaunix.net/uid-21025382-id-168762.html,非常感謝,但原作對于post的處理存在錯誤之處,這里糾正出來。
總結
以上是生活随笔為你收集整理的linux shell cgi post,linux下shell处理cgi的方法--post get的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个女生微信的个性签名。
- 下一篇: linux 命令窗口美化,美化你的命令行