开发者

c cgi how to get form

how to get form input(POST) with following conditions?

1. not hard code the content length

2. a function with provided param which is the form elements name, finally return the string

i can't find any example on interne开发者_如何学Got~

thanks


A CGI script written in C reads POST data from stdin. The content length is written by the HTTP server in the CONTENT_LENGTH environment variable and the script can use getenv to read it.

Unless you're doing some kind of homework, there are much easier ways to do CGI scripting these days (python, php, etc).

Reference: The Common Gateway Interface (CGI) Version 1.1


In addition to what diciu writes:

You also have to take the Content-Type into account, which can be either application/x-www-form-urlencoded or multipart/form-data.


Yes, i'm student, learning c~ don't have idea

void getInput2 () {

char *input;
int len;

len = atoi(getenv("CONTENT_LENGTH"));

fgets(input, len+1, stdin);
printf("%s", input[1]); //error

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜