溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CGI頭聲明格式:Context-Type與Content-

發(fā)布時(shí)間:2020-07-13 13:50:19 來(lái)源:網(wǎng)絡(luò) 閱讀:7823 作者:虎皮喵的喵 欄目:系統(tǒng)運(yùn)維

同樣是POST模式下,開頭聲明的printf格式Context-Type與Content-Type卻有很大不同.

Context-Type:  printf("Context-Type:text/html;charset=UTF-8\n\n"); -----網(wǎng)頁(yè)不識(shí)別html格式語(yǔ)言,都原樣輸出在網(wǎng)頁(yè)上.如果cgi里面沒有html格式語(yǔ)言,只是做其他處理,對(duì)結(jié)果沒有影響.

CGI頭聲明格式:Context-Type與Content-


Content-Type:    printf("Content-Type:text/html;charset=UTF-8\n\n"); ----網(wǎng)頁(yè)會(huì)識(shí)別html語(yǔ)言

CGI頭聲明格式:Context-Type與Content-

代碼如下:

#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)
{
    //聲明網(wǎng)頁(yè)格式
    //printf("Content-Type:text/html;charset=UTF-8\n\n");
    printf("Context-Type:text/html;charset=UTF-8\n\n");
    
    //獲取網(wǎng)頁(yè)響應(yīng)
    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;    
    
    
    //顯示本人設(shè)備信息內(nèi)容
    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("<h3 style=\"text-align:center\"> 服務(wù)器繁忙,請(qǐng)稍后 </h3>\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]);
            //存儲(chǔ)表格原信息
            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>設(shè)備名稱</th>");
    printf("    <th>設(shè)備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>");
    
    //釋放查詢結(jié)果空間
    sqlite3_free_table(result);
    
    //關(guān)閉SQL
    sqlite3_close(ppdb);

    //按鍵 選擇跳轉(zhuǎn)其他頁(yè)面
    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;
}



向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI