gpt4 book ai didi

lisp - 为什么python脚本无法从hunchentoot-cgi获取post参数?

转载 作者:太空宇宙 更新时间:2023-11-03 19:02:35 26 4
gpt4 key购买 nike

hunchentoot-cgi 现在基本上可以与 hunchentoot-1.2.2 一起使用,只需进行一些修改:

  1. #'handle-cgi-script 中,将 :external-format tbnl::+latin-1+ 替换为 :external-format tbnl::+utf-8+
  2. 按照 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 脚本:

  • 获取 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/)
  • POST 到 /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”是错误的,不是吗?

请指点一下,谢谢!

最佳答案

在对 hunchentoot-cgi.lisp 进行了困惑的修改之后,它现在可以工作了。但是,希望它对 Cyrus Harmon (http://cyrusharmon.org/blog) 发布下一个规范版本有所帮助。

>diff cgi.lisp /media/E/RnD/clisp/hunchentoot-cgi/hunchentoot-cgi.lisp
71c71
< (let ((time (or (file-write-date path) (get-universal-time))) (query-string (content-length nil))
---
> (let ((time (or (file-write-date path) (get-universal-time))))
77,83d76
< (if (member (request-method *request*) *methods-for-post-parameters* :test #'eq)
< (progn
< (setq query-string (format nil "~{~A~^&~}" (mapcar (lambda (x) (format nil "~A=~A" (car x) (tbnl:url-encode (cdr x)))) (tbnl:post-parameters*))))
< (setq content-length (parse-integer (header-in :content-length *request*)))
< )
< (setq query-string (tbnl:query-string*)))
<
87c80,81
< . ,(format nil "hunchentoot/~A" hunchentoot-asd:*hunchentoot version*))
---
> . (format nil "hunchentoot/~A"
> hunchentoot-asd:*hunchentoot-version*))
97c91,92
< #+nil ("REMOTE_HOST" . "FIXME!")
---
> ("QUERY_STRING" . ,(tbnl:query-string*))
> #+nil ("REMOTE_HOST" . "FIXME!")
101,106c96
< ("PATH" . ,(sb-unix::posix-getenv "PATH"))
< ("QUERY_STRING" . ,query-string)
< ("CONTENT_TYPE" . ,(header-in :content-type *request*))
< ("CONTENT_LENGTH" . ,content-length)
< ;("HTTP_COOKIE" . ,(tbnl:cookies-out*))
< ("HTTP_COOKIE" . "userid=xxx")
---
>
112,113c102,103
< ("HTTP_REFERER" . ,(tbnl:referer))))))
< (format t "ENV is ~A~%" env)
---
> ("HTTP_REFERER" . ,(tbnl:referer))))))
>
125c115
< :external-format tbnl::+utf-8+)))
---
> :external-format tbnl::+latin-1+)))
128d117
< (format t "ERROR: ~A~%" error) ("HTTP_REFERER" . (tbnl:referer))))))
< (format t "ENV is ~A~%" env)

此致!

关于lisp - 为什么python脚本无法从hunchentoot-cgi获取post参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8767111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com