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 internet~
thanks
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 internet~
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).
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
}