如何检索表单“POST"通过用 C 编写的 cgi-bin 程序获取数据 [英] How to retrieve form "POST" data via cgi-bin program written in C

查看:45
本文介绍了如何检索表单“POST"通过用 C 编写的 cgi-bin 程序获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用用 C 编写的程序从 html 表单中检索 POST 数据.

I am trying to retrieve POST data from html form using program written in C.

目前我正在使用:

char *formdata = getenv("QUERY_STRING");
if(formdata == NULL) /* no data retrieved */

这似乎适用于表单GET"方法,但不适用于POST"方法.如何检索 POST 数据?

This seems to be working fine with form "GET" method but not with "POST" method. How do I retrieve POST data?

推荐答案

POST 数据附加到请求标头,在双换行符之后.在 CGI-BIN 环境中,您从 STDIN 读取它.

POST data is appended to the request header, after a double newline. In a CGI-BIN environment, you read it from STDIN.

请注意,服务器不需要在 POST 数据的末尾向您发送 EOF 字符(或某些终止指示符).永远不要读取超过 CONTENT_LENGTH 个字节.

Be warned that the server IS NOT REQUIRED to send you an EOF character (or some termination indicator) at the end of the POST data. Never read more than CONTENT_LENGTH bytes.

这篇关于如何检索表单“POST"通过用 C 编写的 cgi-bin 程序获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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