小记
今天继续在仿网关系统
笔记
CGI接收Web传递的get\post请求
淘到的相关博客:
这篇讲了一下CGI接收get/post的原理及方法:
https://blog.csdn.net/guodongxiaren/article/details/50569675?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase
这篇中又一些环境变量的含义:
https://blog.csdn.net/dsg333/article/details/9674723?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-3
当前端页面通过get或post方法向cgi程序提交了数据以后,那么接下来cgi程序该如何解析呢?答案是环境变量。无论是Linux系统或Windows系统都有环境变量的概念。Linux用户在配置很多环境的时候,都不得不在系统配置文件中和环境变量打交道。CGI程序即是通过从环境变量中取值来获得参数的。
这里还有一篇讲CGI环境变量的博客:
https://blog.csdn.net/zhouzhenhe2008/article/details/77248489
当然这都是比较原始的方法
这里有篇讲工具(CGIC库)的博客:
https://www.cnblogs.com/programmer-wfq/p/5582114.html
仿网关项目记录
我想搞的是将网关项目的各项搞一个五级分层的树
然后每一层都可以查看相应的详细信息
在搞这个五级分层的树,需要用到动态获取各个分支的内容,逐步完善各级的cgi文件
这里有篇讲CGI挺好的博客:
https://blog.csdn.net/yand789/article/details/38111667
折腾了一段时间总算把 devices[]给取出来了:
CGI程序:
#include<stdio.h>
#include<stdlib.h>
#include "cgic.c"
int cgiMain(){
char input[200];
char **dervices;
char * lenstr = getenv("CONTENT_LENGTH");
fgets(input,201,stdin);
printf("Content-type: application/html\r\n\r\n");
printf("%s\n",lenstr);
printf("%s\n",input);
cgiFormStringMultiple("dervices[]",&dervices);
for(int i=0;i<4;i++){
printf("%s",&dervices[i][0]);
}
}