简体   繁体   English

如何在C ++中从命令行获取CGI表单数据

[英]how to get CGI form data from the command line in C++

I'm just starting to try and learn CGI programming. 我刚刚开始尝试学习CGI编程。 I have a simple webpage with a form. 我有一个带有表单的简单网页。 The form has two input fields asking for a number. 该表格有两个输入字段,要求输入数字。

Im just trying to figure out how to use the command line to send the numbers in the text boxes to my CGI program, multiply them, and cout the result. 我只是想弄清楚如何使用命令行将文本框中的数字发送到我的CGI程序,将它们相乘并得出结果。

WITHOUT using an external library, how do I get the input from the form? 不使用外部库,如何从表单获取输入?

If I remember correctly, you have to check environment for QUERY_STRING 如果我没记错的话,您必须检查环境QUERY_STRING

so if CGI passes you string some_path?var1=a&var2=b then you could do 因此,如果CGI向您传递字符串some_path?var1=a&var2=b那么您可以

char* query = getenv("QUERY_STRING");
// query will be set to "var1=a&var2=b"

int a = atoi( ... ); // some code to find var1 and get "a" as a string
int b = atoi( ... ); // some code to find var2 and get "b" as a string

fprintf("%d", a+b);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM