cgi
2015-12-31 16:54
183 查看
在web端用F12也可以查看network:GET post的情况。cgi代码并不长,区分以下普通和文件的上传:x-www-form-urlencoded与multipart/form-data区别。
cgiGetenv(&cgiServerSoftware, (char*)"SERVER_SOFTWARE");//lighttpd/1.4.35 ---明显取得web服务器以及版本
cgiGetenv(&cgiServerName, (char*)"SERVER_NAME");//192.168.59.254 ---域名
cgiGetenv(&cgiGatewayInterface, (char*)"GATEWAY_INTERFACE");//CGI/1.1 ---CGI通用网关结构
cgiGetenv(&cgiServerProtocol, (char*)"SERVER_PROTOCOL");//HTTP/1.1 ---服务器协议版本
cgiGetenv(&cgiServerPort, (char*)"SERVER_PORT");//80 ---端口
cgiGetenv(&cgiRequestMethod, (char*)"REQUEST_METHOD");//GET ---web请求方法。GET,SET我也不是很熟
cgiGetenv(&cgiPathInfo, (char*)"PATH_INFO");//NULL
cgiGetenv(&cgiPathTranslated, (char*)"PATH_TRANSLATED");//NULL
cgiGetenv(&cgiScriptName, (char*)"SCRIPT_NAME");///cgi-bin/login.cgi ----调用的脚本名字
cgiGetenv(&cgiQueryString, (char*)"QUERY_STRING");//NULL ----请求的数据,如action=login&username=Administrator&password=WiDi
cgiGetenv(&cgiRemoteHost, (char*)"REMOTE_HOST");//192.168.59.40 ----远端主机名
cgiGetenv(&cgiRemoteAddr, (char*)"REMOTE_ADDR");//NULL
cgiGetenv(&cgiAuthType, (char*)"AUTH_TYPE");//NULL
cgiGetenv(&cgiRemoteUser, (char*)"REMOTE_USER");//NULL
cgiGetenv(&cgiRemoteIdent, (char*)"REMOTE_IDENT");//NULL
............................................................
cgiGetenv(&cgiContentLengthString, (char*)"CONTENT_LENGTH");//0 ---访问时内容长度
cgiContentLength = atoi(cgiContentLengthString);
cgiGetenv(&cgiAccept, (char*)"HTTP_ACCEPT");//text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ---应该是可以接收的格式。html,xhtml,xml(猜的)。
cgiGetenv(&cgiUserAgent, (char*)"HTTP_USER_AGENT");//Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0 ---访问代理Firefox
cgiGetenv(&cgiReferrer, (char*)"HTTP_REFERER");//http://192.168.59.254/index.html ---web访问的地址
cgiGetenv(&cgiCookie, (char*)"HTTP_COOKIE");//lang=English; SESSIONID=E85F333900B0B4586A0E25A1CC9B0A21 ---与web端会话ID
对应输出结果:
SERVER_SOFTWARE==lighttpd/1.4.35
SERVER_NAME==192.168.59.254
GATEWAY_INTERFACE==CGI/1.1
SERVER_PROTOCOL==HTTP/1.1
SERVER_PORT==80
REQUEST_METHOD==GET
SCRIPT_NAME==/cgi-bin/login.cgi
REMOTE_ADDR==192.168.59.40
CONTENT_LENGTH==0
HTTP_ACCEPT==text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENT==Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0
HTTP_REFERER==http://192.168.59.254/index.html
HTTP_COOKIE==lang=English; SESSIONID=E85F333900B0B4586A0E25A1CC9B0A21
Web session invalid
如果REQUEST_METHOD==POST说明是设置命令如:SET http://localhost/Jack/cgi-bin/out.cgi?theText=it%27s+me
其中theText是html/javascript中定义的输入接口名称。it%27s+me为输入的内容。
对应函数:cgiParseFormInput
typedef struct cgiFormEntryStruct {
char *attr;//属性名,html中定义的,保存在这里POST上传
/* value is populated for regular form fields only.
For file uploads, it points to an empty string, and file
upload data should be read from the file tfileName. */
char *value;//对应的数据
/* When fileName is not an empty string, tfileName is not null,
and 'value' points to an empty string. */
/* Valid for both files and regular fields; does not include
terminating null of regular fields. */
int valueLength;//数据长度
char *fileName;
char *contentType;
/* Temporary file name for working storage of file uploads. */
char *tfileName;
struct cgiFormEntryStruct *next;//下一个组上传属性。表头cgiFormEntryFirst
} cgiFormEntry;
cgiStrEqNc判断字符串相等。
cgiParsePostFormInput从cgin读取数据并解析POST到表头cgiFormEntryFirst
cgiParseGetFormInput从cgiQueryString解析数据到cgiFormEntryFirst
cgiCookies用来提取cgiCookie中如:lang和SESSIONID的名字--不是value
get_cgi_session_id这是用户层代码了,用来查看cgiCookie中是否有SESSIONID信息。
cgiGetenv(&cgiServerSoftware, (char*)"SERVER_SOFTWARE");//lighttpd/1.4.35 ---明显取得web服务器以及版本
cgiGetenv(&cgiServerName, (char*)"SERVER_NAME");//192.168.59.254 ---域名
cgiGetenv(&cgiGatewayInterface, (char*)"GATEWAY_INTERFACE");//CGI/1.1 ---CGI通用网关结构
cgiGetenv(&cgiServerProtocol, (char*)"SERVER_PROTOCOL");//HTTP/1.1 ---服务器协议版本
cgiGetenv(&cgiServerPort, (char*)"SERVER_PORT");//80 ---端口
cgiGetenv(&cgiRequestMethod, (char*)"REQUEST_METHOD");//GET ---web请求方法。GET,SET我也不是很熟
cgiGetenv(&cgiPathInfo, (char*)"PATH_INFO");//NULL
cgiGetenv(&cgiPathTranslated, (char*)"PATH_TRANSLATED");//NULL
cgiGetenv(&cgiScriptName, (char*)"SCRIPT_NAME");///cgi-bin/login.cgi ----调用的脚本名字
cgiGetenv(&cgiQueryString, (char*)"QUERY_STRING");//NULL ----请求的数据,如action=login&username=Administrator&password=WiDi
cgiGetenv(&cgiRemoteHost, (char*)"REMOTE_HOST");//192.168.59.40 ----远端主机名
cgiGetenv(&cgiRemoteAddr, (char*)"REMOTE_ADDR");//NULL
cgiGetenv(&cgiAuthType, (char*)"AUTH_TYPE");//NULL
cgiGetenv(&cgiRemoteUser, (char*)"REMOTE_USER");//NULL
cgiGetenv(&cgiRemoteIdent, (char*)"REMOTE_IDENT");//NULL
............................................................
cgiGetenv(&cgiContentLengthString, (char*)"CONTENT_LENGTH");//0 ---访问时内容长度
cgiContentLength = atoi(cgiContentLengthString);
cgiGetenv(&cgiAccept, (char*)"HTTP_ACCEPT");//text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ---应该是可以接收的格式。html,xhtml,xml(猜的)。
cgiGetenv(&cgiUserAgent, (char*)"HTTP_USER_AGENT");//Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0 ---访问代理Firefox
cgiGetenv(&cgiReferrer, (char*)"HTTP_REFERER");//http://192.168.59.254/index.html ---web访问的地址
cgiGetenv(&cgiCookie, (char*)"HTTP_COOKIE");//lang=English; SESSIONID=E85F333900B0B4586A0E25A1CC9B0A21 ---与web端会话ID
对应输出结果:
SERVER_SOFTWARE==lighttpd/1.4.35
SERVER_NAME==192.168.59.254
GATEWAY_INTERFACE==CGI/1.1
SERVER_PROTOCOL==HTTP/1.1
SERVER_PORT==80
REQUEST_METHOD==GET
SCRIPT_NAME==/cgi-bin/login.cgi
REMOTE_ADDR==192.168.59.40
CONTENT_LENGTH==0
HTTP_ACCEPT==text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENT==Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0
HTTP_REFERER==http://192.168.59.254/index.html
HTTP_COOKIE==lang=English; SESSIONID=E85F333900B0B4586A0E25A1CC9B0A21
Web session invalid
如果REQUEST_METHOD==POST说明是设置命令如:SET http://localhost/Jack/cgi-bin/out.cgi?theText=it%27s+me
其中theText是html/javascript中定义的输入接口名称。it%27s+me为输入的内容。
对应函数:cgiParseFormInput
typedef struct cgiFormEntryStruct {
char *attr;//属性名,html中定义的,保存在这里POST上传
/* value is populated for regular form fields only.
For file uploads, it points to an empty string, and file
upload data should be read from the file tfileName. */
char *value;//对应的数据
/* When fileName is not an empty string, tfileName is not null,
and 'value' points to an empty string. */
/* Valid for both files and regular fields; does not include
terminating null of regular fields. */
int valueLength;//数据长度
char *fileName;
char *contentType;
/* Temporary file name for working storage of file uploads. */
char *tfileName;
struct cgiFormEntryStruct *next;//下一个组上传属性。表头cgiFormEntryFirst
} cgiFormEntry;
cgiStrEqNc判断字符串相等。
cgiParsePostFormInput从cgin读取数据并解析POST到表头cgiFormEntryFirst
cgiParseGetFormInput从cgiQueryString解析数据到cgiFormEntryFirst
cgiCookies用来提取cgiCookie中如:lang和SESSIONID的名字--不是value
get_cgi_session_id这是用户层代码了,用来查看cgiCookie中是否有SESSIONID信息。
相关文章推荐
- Java设计模式透析之 —— 适配器(Adapter)
- automake使用方法
- $each 遍历json字符串
- iOS 真机调试 出现process launch failed: timed out waiting for app to launch 和 failed to get the task for 的
- java 时间解析
- 导出Excel工具类
- AsyncTask原理精简版
- MesaSQLite数据库简单使用
- FragmentTransition replace add show hide方法的使用和差异
- CodeForces 466A Cheap Travel
- GTK+重拾--10 GTK+中的组件(二)
- 量化派重磅推出"量化派开放平台"
- git账户中如何添加SSHkeys
- 把电脑虚拟机linux下编译的程序烧写到ARM9开发板的linux系统里面的具体操作步骤
- 关于在ios7之后改变状态栏颜色
- python 解析xml 文件: Element Tree 方式
- 基于python的Tkinter实现一个简易计算器
- Android中AsyncTask的使用方法解析
- 简明Python学习笔记之二--第一个Hello word!
- Android性能优化——I/O篇