Get the App
SLTechnology News&Howtos  ›  Servers  › 

CGI header declaration format: Context-Type and Content-

Shulou Source: shulou.com Published: 2022-06-02 17:11:47 09月22日 Update

In POST mode, Context-Type and Content-Type are very different.

Context-Type: printf("Context-Type:text/html;charset= UTF-8\n\n"); ----The page does not recognize html format language, all output on the page as is. If there is no html format language in CGI, just do other processing, no impact on the results.

Content-Type: printf("Content-Type:text/html;charset= UTF-8\n\n"); ---HTML language recognized by web pages

The code is as follows:

#include

#include

#include

#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)

{

//Declares web page format

//printf("Content-Type:text/html;charset=UTF-8\n\n");

printf("Context-Type:text/html;charset=UTF-8\n\n");

//Get web page response

int len = atoi(getenv("CONTENT_LENGTH"));

char buf[100]={0};

int ret = fread(buf, 1, 256, stdin);

//Open SQL

sqlite3 *ppdb = NULL;

ret = sqlite3_open("/mnt/hgfs/Share/program3/userinformation.db", &ppdb);

if(ret != SQLITE_OK)

{

printf("

SQLITE OPEN FAIL\n\n");

return -1;

}

char *err = NULL;

char **result = NULL;

//Display the content of my device information

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("\n\n");

printf("\n\n");

printf("Server busy, please wait\n\n");

printf("\n\n");

printf("\n\n");

printf("\n\n");

return -1;

}

int i=0, j=0;

for(i=1; i

Tags: Web page format device language information result different big busy code content as is just name beginning button server mode later Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia OPPO Reno macOS Microsoft