CGI头声明格式:Context-Type与Content-Type的区别

同样是POST模式下,开头声明的printf格式Context-Type与Content-Type却有很大不同.

Context-Type:  printf("Context-Type:text/html;charset=UTF-8\n\n"); -----网页不识别html格式语言,都原样输出在网页上.如果cgi里面没有html格式语言,只是做其他处理,对结果没有影响.

Content-Type:    printf("Content-Type:text/html;charset=UTF-8\n\n"); ----网页会识别html语言

代码如下:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sqlite3.h"

#define SQL_SELECT "select name, devid, devname from userinfo where username='sume';"

struct __userinfo{
    char name[20];
    char dearname[20];
    char telephone[12];
    char address[200];
    char devid[26];
    char devname[20];
}user;

int main(void)
{
    //声明网页格式
    //printf("Content-Type:text/html;charset=UTF-8\n\n");
    printf("Context-Type:text/html;charset=UTF-8\n\n");
    
    //获取网页响应
    int len = atoi(getenv("CONTENT_LENGTH"));
    char buf[100]={0};
    int ret = fread(buf, 1, 256, stdin);
    
    //打开SQL
    sqlite3 *ppdb = NULL;
    ret = sqlite3_open("/mnt/hgfs/Share/program3/userinformation.db", &ppdb);
    if(ret != SQLITE_OK)
    {
        printf("<p>SQLITE OPEN FAIL\n\n");
        return -1;
    }
    char *err = NULL;
    char **result = NULL;    
    
    
    //显示本人设备信息内容
    int row = 0, col = 0;
    result = NULL;
    ret = sqlite3_get_table(ppdb, SQL_SELECT, &result, &row, &col, &err);    
    if(ret != SQLITE_OK)
    {
        printf("SEE FAIL : %s\n", err);
        sqlite3_close(ppdb);
        printf("<body>\n\n");
        printf("<meta http-equiv=\"content-Type\"content=\"text/html;charset=UTF-8\">\n\n");
        printf("<h2 style=\"text-align:center\"> 服务器繁忙,请稍后 </h2>\n\n");
        printf("<center><input type=\"button\" value=\"返回\" onclick=\"window.location.href='http://192.168.14.200/M_userface.html'\">\n\n");
        printf("<input type=\"button\" value=\"退出\" onclick=\"window.location.href='http://192.168.14.200/M_login.html'\"></center>\n\n");
        printf("</body>\n\n");
        
            return -1;
    }
    
    
    int i=0, j=0;
    for(i=1; i<(row+1); i++)
    {
        for(j=0; j<col; j++)
        {
            //printf("%s ", result[i*col+j]);
            //存储表格原信息
            switch(j)
            {
                case 0: strcpy(user.name, result[i*col+j]);break;
                case 1: strcpy(user.devid, result[i*col+j]);break;
                case 2: strcpy(user.devname, result[i*col+j]);break;
            }

}
        //printf("\n\n");
    }
    
    printf("<br> </br>");
    printf("<br> </br>");
    printf("<br> </br>");
    printf("<br> </br>");
    printf("<center><table border=\"1\" cellpadding=\"10\" cellspacing=\"0\"></center>");
    printf("<tr>");
    printf("    <th>姓名</th>");
    printf("    <th>设备名称</th>");
    printf("    <th>设备ID</th>");
    printf("</tr>");
    printf("<tr>");
    printf("    <td>%s</td>", user.name);
    printf("    <td>%s</td>", user.devname);
    printf("    <td>%s</td>", user.devid);
    printf("</tr>");
    printf("</table>");
    
    //释放查询结果空间
    sqlite3_free_table(result);
    
    //关闭SQL
    sqlite3_close(ppdb);

//按键 选择跳转其他页面
    printf("<body>");
    printf("<meta http-equiv=\"content-Type\"content=\"text/html;charset=UTF-8\">\n\n");
    printf("<center><table border=\"0\" cellpadding=\"10\" cellspacing=\"0\"></center>");
    printf("<tr>");
    printf("<td><input type=\"button\" value=\"返回\" onclick=\"window.location.href='http://192.168.14.200/M_userface.html'\"></td>");
    printf("<td><input type=\"button\" value=\"退出\" onclick=\"window.location.href='http://192.168.14.200/M_login.html'\"></td>");
    printf("</tr>");
    printf("</table>");
    printf("</body>");
    
    return 0;
}

时间: 2024-08-30 04:23:06

CGI头声明格式:Context-Type与Content-Type的区别的相关文章

Element &#39;beans&#39; cannot have character [children],because the type&#39;s content type is element

配置文件错误—— Element 'beans' cannot have character [children],because the type's content type is element 意为 beans 标签下只能存在子元素节点,不能存在文本符号 当编译器放生这种错误时,就是配置文件发生错误.这种错误有两种情况. 1.简单错误:仔细观察代码,有时可能是存在一个文本符号 2.难以发现的错误:核实代码,完全没有文本符号,就有可能是编码问题,将整段拷贝,用notepad++打开,使用A

pom文件出现Element &#39;xxxxxxx&#39; cannot have character [children],because the type&#39;s content type is element-only问题

1)问题描述: pom.xml文件中出现 Element 'xxxxxxx' cannot have character [children],because the type's content type is element-only. 2)问题原因: 配置文件中的dependencies节点下面只能是元素节点,不能有字符或文本存在. 3)解决方法: 仔细检查文档,可能会存在标点符号,空格等其他文本字符. pom文件出现Element 'xxxxxxx' cannot have charac

Spring MVC 前后台传递json格式数据 Content type &#39;application/x-www-form-urlencoded;charset=UTF-8&#39; not supported

报错如下: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 解决方案: 引入如下包: 问题既解决. Spring MVC 前后台传递json格式数据 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

the request doesn&#39;t contain a multipart/form-data or multipart/form-data stream, content type header

the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header 一,HTTP上传的基本知识 在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型.下边是说明: application/x-www-form-urlencoded: 窗体数据被编码为名称/值对.这是标准的编码格式. mult

Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 错误信息: Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or applic

Package should contain a content type part [M1.13]

public static Workbook create(InputStream in) throws         IOException,InvalidFormatException {        if (!in.markSupported()) {            in = new PushbackInputStream(in, 8);        }        if (POIFSFileSystem.hasPOIFSHeader(in)) {            r

SharePoint Development - Custom Content Type using Visual Studio 2010 based SharePoint 2010

本文所述均来自之前实际的项目模块 首先再论述一下SharePoint ContentType内容类型 SharePoint的列表和文档库可以储存不同类型的内容就叫做内容类型,比如文档库的文档,调查列表的调查等,都称作是内容类型.内容类型在网站范围内是可用的,不同的内容类型具有不同的内容和设置(如策略,关联的工作流等). 通俗来讲,内容类型可以是文档,可以是文件夹,也可以是字段的集合.创建好后的内容类型可以与列表关联,体现在列表的新建项目上.没有凭空而来的内容类型,任何自定义内容类型都是基于现有类

Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/

用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static void testOuGuanMatch() throws IOException{        Document doc = Jsoup.connect("我的URL").userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1;

postman测试接口报Content type &#39;text/plain;charset=UTF-8&#39; not supported解决方法

增加一个请求头管理器,添加content-type:application/json.并将请求修改为json数据传输试试. 参考:https://zhidao.baidu.com/question/1644957725975214740.html postman测试接口报Content type 'text/plain;charset=UTF-8' not supported解决方法 原文地址:https://www.cnblogs.com/xiaoni-fighting/p/12298436.