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

    点击提交后,效果为:

  • 相关阅读:
    MySql8安装使用中的一些注意
    如何在CentOS 8主机上安装Nginx Web服务器
    centos安装sqlserver
    VSCode快捷键
    C#中的委托
    Winform加载loading界面
    JayRock的一些用法:json and json rpc for .Net
    winform picturebox控件 定时让图片轮播
    sql server创建存储过程
    ftp上传单一文件示例
  • 原文地址:https://www.cnblogs.com/wddx5/p/13223236.html
Copyright © 2011-2022 走看看