在httpRequester發出POST時,可以由兩種返回參數(提交參數)的方式。
1是在URL裏;2是在content裏。
如下圖
在CGI中進行接收時,對兩種方式的接收方式也不一樣。
URL後面的參數由HTTP服務器放到全局變量QUERY_STRING裏帶給cgi.
content裏的則由HTTP服務器啓動CGI後,使用stdin發給CGI。由CGI read stdin來得到。
代碼如下:
post_length = tonumber(os.getenv("CONTENT_LENGTH")) or 0;
if os.getenv("REQUEST_METHOD") == "POST" and post_length > 0 then
my_log("POST method\n");
post_raw = io.read(post_length);
my_log("posw_raw:\n" .. post_raw .. "\n");
end
日誌文件如下:
POST method
posw_raw:
ip=22.2.22.2