test_form.c
上传用户:ladybrid91
上传日期:2007-01-04
资源大小:287k
文件大小:1k
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- int main(int argc, char **argv)
- {
- int i;
- time_t bt;
- char *cp;
- char buf[256];
- int len;
-
- time(&bt);
-
- printf("Content-Type: text/htmlnn");
- printf("<HTML><BODY>n");
- printf("<B>Test av forms/post</B><P>n");
- if ((cp = getenv("REQUEST_METHOD")))
- printf("<B>REQUEST_METHOD</B> = %s<BR>n", cp);
- if (cp && (strcmp(cp, "PUT") == 0 || strcmp(cp, "POST") == 0))
- {
- printf("<HR>n");
- cp = getenv("CONTENT_LENGTH");
- if (cp)
- {
- len = atoi(cp);
- fread(buf, 1, len, stdin);
- buf[len] = ' ';
- printf("<B>Data:</B> %sn", buf);
- }
- else
- printf("No content-length definedn");
-
- printf("<HR>n");
- }
-
- {
- char *cp = getenv("QUERY_STRING");
- if (cp)
- printf("<BR>QUERY_STRING 鋜: %s<BR>n", cp);
- }
-
- if (argv)
- {
- printf("Argumenten till mig 鋜:n");
- printf("<UL>n");
- for (i = 0; argv[i]; i++)
- printf("<LI>%sn", argv[i]);
- }
- else
- printf("Inga argument till mig idag.n");
- printf("<FORM METHOD=GET ACTION="%s">n", getenv("SCRIPT_NAME"));
- printf("<UL>n");
- printf("<LI><INPUT TYPE="test" NAME="foo" MAXLENGTH="10">n");
- printf("</UL>n");
- printf("<INPUT TYPE="submit">n");
- printf("</FORM>n");
-
- printf("</BODY></HTML>n");
- return 0;
- }