zoukankan      html  css  js  c++  java
  • CGIC库之get与post请求一

    get请求demo:

    login.html文件,放到/boa/www/ 下

    <html>
        <head>
            <title>Test</title>
        </head>
        <body>
            <form action="cgi-bin/login.cgi" method="get">
               <input type="text" name="theText">
               <input type="submit" value="Continue">
           </form>
       </body>
       </html>

    新建文件夹,放入新建的login.c,再拷贝cgic.h  cgic.h在当前文件夹下,

    login.c内容:

    #include <stdio.h>
    #include "cgic.h"
    #include <string.h>
    #include <stdlib.h>
    
     extern char *cgiQueryString;
    int cgiMain() {
         cgiHeaderContentType("text/html");
         fprintf(cgiOut, "<HTML><HEAD>/n");
         fprintf(cgiOut, "<TITLE>My CGIC</TITLE></HEAD>/n");
         fprintf(cgiOut, "<BODY>");
         fprintf(cgiOut, "<H1>%s</H1>",cgiQueryString);
        fprintf(cgiOut, "</BODY>/n");
       fprintf(cgiOut, "</HTML>/n");
        return 0;
     }

    新建Makefile文件:

    login.cgi:cgic.h cgic.c
        gcc login.c cgic.c -o login.cgi
    
    clean:
        rm -f *.o *.a *.cgi 

    执行 make,将生成的login.cgi放入cgi-bin目录中,运行启动boa服务器:./boa

    浏览器中输入:  http://192.168.1.103/login.html

    得到界面

     点击Continue后得到

     get请求会在URL中附带明文,这样缺少保密性,故用post请求。

    POST请求demo:

     login.html

    <html>
        <head>
            <title>Test</title>
        </head>
        <body>
            
          <form action="cgi-bin/login.cgi" method="POST">
            <input type="text" name="name" />
            <input type="text" name="number" />
            <input type="submit" value="Submit" />
             
           </form>
       </body>
       </html>

    login.c

     #include <stdio.h>
     #include "cgic.h"
     #include <string.h>
      #include <stdlib.h>
    
     int cgiMain() {
        char name[241];
        char number[241];
        cgiHeaderContentType("text/html");
        fprintf(cgiOut, "<HTML><HEAD>
    ");
         fprintf(cgiOut, "<TITLE>My CGI</TITLE></HEAD>
    ");
          fprintf(cgiOut, "<BODY>");
         cgiFormString("name", name, 241);
        cgiFormString("number", number, 241);
        fprintf(cgiOut, "<H1>%s</H1>",name);
         fprintf(cgiOut, "<H1>%s</H1>",number);
        fprintf(cgiOut, "</BODY>
    ");
          fprintf(cgiOut, "</HTML>
    ");
        return 0;
     }
     
     
     

    make  后,拷贝生成的login.cgi到cgi-bin目录下, 浏览器输入可查看效果:http://192.168.1.103/login.html

    点击提交后,效果为:

  • 相关阅读:
    linux nat路由设置
    [auv] 模拟呼叫
    Sqlserver 导出insert插入语句
    函数name属性
    学习前端,应该选择哪些书籍来看?(转)
    JavaScript继承学习笔记
    Web响应式网站
    Javascript 异步加载详解(转)
    使用 nodeinspector 调试 Node.js
    用 JavaScript 检测 CPU 占比(转)
  • 原文地址:https://www.cnblogs.com/wddx5/p/13223236.html
Copyright © 2011-2022 走看看