test_post.c

来自「程序代码使用说明: (1)所有源代码目录下都提供了Makefile(非Qt)」· C语言 代码 · 共 46 行

C
46
字号
#include <stdio.h>#include <stdlib.h>#define MAX_ARG 150#define MAX_CONTENT 1024int main(){    int content_length = atoi(getenv("CONTENT_LENGTH"));    char content[MAX_CONTENT];    fgets(content, content_length + 1, stdin);        char para1[MAX_ARG], para2[MAX_ARG];    char value1[MAX_ARG], value2[MAX_ARG];    /* parse '&' */    char *p = strchr(content, '&');    *p = '\0';    strcpy(para1, content);    strcpy(para2, p + 1);    /* parse the first '=' */    p = strchr(para1, '=');    *p = '\0';    strcpy(value1, p + 1);        /* parse the second '=' */    p = strchr(para2, '=');    *p = '\0';    strcpy(value2, p + 1);       printf("Content-type: text/html\n\n");    printf("<HTML><HEAD><TITLE>CGI TEST RESULT</TITLE></HEAD>\n");    printf("<BODY><H2>Get test string from POST</H2><PRE>\n");    printf("The first parameter is: %s\n<p>", para1);    printf("The first value is: %s\n<p>", value1);    printf("The second parameter is: %s\n<p>", para2);    printf("The second value is: %s\n<p>", value2);    printf("</PRE></BODY></HTML>\n");    fflush(stdout);    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?