CGI POST Method
in place June,21 2000, last modified June 21, 2000
CGI POST Method Example: HTML
<HTML>
<HEAD>
<TITLE> POST METHOD CGI </TITLE>
<BODY>
<H1>POST METHOD</H1>
<FORM ACTION="/cgi-bin/cgi.cgi" METHOD="POST">
PIZ <INPUT TYPE="TEXT" NAME=PIZZA ><BR>
TOP <INPUT TYPE=TEXT NAME=TOPPING><BR>
ETC <INPUT TYPE=TEXT NAME=ETC><BR>
<INPUT TYPE=SUBMIT VALUE=GO>
</FORM>
</BODY>
</HTML>
CGI POST Method Example: C Code
cgi.c file main() printf("Content-type : text/html\n\n"); printf("<H1>VICS INTERFACE</H1>"); }
#include
#include "typedef.h"
{
int count;
entry entries[5];
printf("<HTML><BODY>");
post_method(entries,&count);
printf(" %s : %s <BR>", entries[0].name,entries[0].val);
printf(" %s : %s <BR>", entries[1].name,entries[1].val);
printf("</BODY></HTML>");
getp.c file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "typedef.h"
char *fmakeword(FILE *f, char stop, int *len);
void plustospace(char *str);
void unescape_url(char *url);
char *makeword(char *line, char stop);
void post_method(entry entries[], int *post_cell_count)
{
int x;
int cl;
if(strcmp(getenv("REQUEST_METHOD"),"POST"))
printf("You request the page with %s method <BR>",getenv("REQUEST_METHOD"));
printf("This script should be referenced with a METHOD of POST.\n");
exit(1);
}
if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded"))
printf("This script can only be used to decode from results.\n");
exit(1);
}
cl = atoi(getenv("CONTENT_LENGTH"));
printf(" length = %d <BR>",cl);
for (x=0; cl && (!feof(stdin)); x++)
*post_cell_count = x;
entries[x].val = fmakeword(stdin,'&',&cl);
plustospace(entries[x].val);
unescape_url(entries[x].val);
entries[x].name=makeword(entries[x].val,'=');
}
}
util.c file /*----------------------------- word[x] = '\0'; while(line[y++] = line[x++]); wsize = 102400; /*----------------------------- digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); for (x=0, y=0;url[y];++x,++y) /*----------------------------- for (x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; /*----------------------------- /*----------------------------- while(1) if(s[i] == CR) if((s[i] == 0x4) oror (s[i] == LF) oror (i == (n-1)))
#include <stdio.h>
#define LF 10
#define CR 13
makeword
------------------------------*/
char *makeword(char *line, char stop)
{
int x = 0, y;
char *word = (char *) malloc(sizeof(char) * (strlen(line)+1));
for(x=0;((line[x]) && (line[x]!=stop));x++)
word[x] = line[x];
if(line[x]) ++x;
y = 0;
return word;
}
/*-----------------------------
fmakeword
------------------------------*/
char *fmakeword(FILE *f, char stop, int *cl)
{
int wsize;
char *word;
int ll;
ll = 0;
word = (char *) malloc(sizeof(char) * (wsize+1));
while(1)
{
word[ll] = (char) fgetc(f);
if(ll==wsize) {
word[ll+1] = '\0';
wsize+=102400;
word = (char *)realloc(word,sizeof(char)*(wsize+1));
}
--(*cl);
if((word[ll] == stop) oror (feof(f)) oror (!(*cl))) {
if(word[ll] != stop) ll++;
word[ll] = '\0';
return word;
}
++ll;
}
}
x2c
------------------------------*/
char x2c(char*what)
{
register char digit;
digit *= 16;
digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
return(digit);
}
/*-----------------------------
unescape_url
------------------------------*/
void unescape_url(char *url)
{
register int x,y;
{
if((url[x] = url[y]) == '%')
{
url[x] = x2c(&url[y+1]);
y+=2;
}
}
url[x] = '\0';
}
plustospace
------------------------------*/
void plustospace(char *str)
{
register int x;
}
rind
------------------------------*/
int rind(char *s, char c)
{
register int x;
for (x=strlen(s) - 1;x != -1;x--)
if(s[x] == c) return x;
return -1;
}
getline
------------------------------*/
int getline(char *s, int n, FILE *f)
{
register int i=0;
{
s[i] = (char)fgetc(f);
s[i] = fgetc(f);
{
s[i] = '\0';
return (feof(f) ? 1 :0);
}
++i;
}
}
typedef.h typedef struct { 출처: http://engdb.tripod.com/kedb/kms/knowledge/20000621.htm /start.cgi?address=/~gunman/cgi-bin/airpage/pds2/data/language-14.htm&forward=yes
typedef struct {
char *name;
char *val;
} entry;
char name[21];
char val[50];
} gentry;
관련자료:
util.c 부분입니다.