hunchentoot-cgi 现在基本上可以与 hunchentoot-1.2.2 一起使用,但需要进行一些修改:
- 中
#'handle-cgi-script
,替换:external-format tbnl::+latin-1+
为:external-format tbnl::+utf-8+
正如 WhiteCat 建议的那样,使用
#'make-pathname
如下:(pushnew (hunchentoot-cgi::create-cgi-dispatcher-and-handler "/cgi-bin/" (make-pathname :directory '(:absolute "media" "E" "myapp" "cgi-bin"))) dispatch-table :test #'equal)
但是,我不明白为什么python脚本无法获取POSTed参数,即访问时http://127.0.0:8000/cgi-bin/login.py?cmd=view
,login.py可以成功获取参数cmd
的值,但是当通过以下表单发布时,login.py无法获取所有发布的值(无论是否隐藏):
<html><body>
<form method='POST' action='cgi-bin/login.py'>
<input type='text' name='userid'>
<input type='password' name='userpwd'>
<input type='submit' value='Login'>
<input type='hidden' name='cmd' value='view'>
</form>
</body></html>
我猜 hunchentoot-cgi 没有根据环境将发布的参数传递给 python 脚本:
GET http://127.0.0.1:8000/cgi-bin/nav.py?userid=xyz&cmd=view
传递给python脚本的环境是:(SERVER_SOFTWARE=hunchentoot/1.2.2 SERVER_NAME=127.0.0.1 GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT=8000 REQUEST_METHOD=GET CONTENT_TYPE=text/html CONTENT_LENGTH=NIL SCRIPT_NAME=/cgi-bin/nav.py QUERY_STRING=userid=xyz&cmd=view REMOTE_ADDR=127.0.0.1 HTTP_HOST=NIL REQUEST_URI=/cgi-bin/nav.py?userid=xyz&cmd=view SERVER_ADDR=NIL HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 HTTP_REFERER=http://127.0.0.1:8000/)
邮寄到
/cgi-bin/nav.py
(SERVER_SOFTWARE=hunchentoot/1.2.2 SERVER_NAME=127.0.0.1 GATEWAY_INTERFACE=CGI/1.1 SERVER_PROTOCOL=HTTP/1.1 SERVER_PORT=8000 REQUEST_METHOD=POST CONTENT_TYPE=text/html CONTENT_LENGTH=NIL POST_PARAMETERS=((userid . xyz) (userpwd . 123) (cmd . view)) SCRIPT_NAME=/cgi-bin/nav.py QUERY_STRING=NIL REMOTE_ADDR=127.0.0.1 HTTP_HOST=NIL REQUEST_URI=/cgi-bin/nav.py SERVER_ADDR=NIL HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
我认为“CONTENT_LENGTH=NIL”是错误的,不是吗?
请大神指点一下,谢谢!