Использование технологий WWW для доступа к базам данных



         

Примеры cgi-модулей - часть 2


GATEWAY_INTERFACE = CGI/1.1

SERVER_PROTOCOL = HTTP/1.0

SERVER_PORT = 80

REQUEST_METHOD = POST

HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,*/*

PATH_INFO =

PATH_TRANSLATED =

SCRIPT_NAME = /cgi-bin/test-cgi

QUERY_STRING =

REMOTE_HOST = fwa.cnit.nsu.ru

REMOTE_ADDR = 193.124.209.74

REMOTE_USER =

AUTH_TYPE =

CONTENT_TYPE = application/x-www-form-urlencoded

CONTENT_LENGTH = 142

Результат работы post-query:

<H1>Query Results</H1>You submitted the following

name/value pairs:<p>


<ul>


<li> <code>RealName = Петров Иван Сидорович</code>


<li> <code>Sex = Мужской</code>


<li> <code>Submit = Послать запрос </code>


</ul>

И на экране браузера

Query Results

You submitted the following name/value pairs:

RealName = Петров Иван Сидорович

Sex = Мужской

Submit = Послать запрос

Ниже приведен исходный текст программы post-query.

#include <stdio.h>

#ifndef NO_STDLIB_H

#include <stdlib.h>

#elsechar *getenv();

#endif

#define MAX_ENTRIES 10000

typedef struct {

char *name;

char *val;

} entry;

char *makeword(char *line, char

stop);

char *fmakeword(FILE *f, char

stop, int *len);

char x2c(char *what);

void unescape_url(char *url);

void plustospace(char *str);

main(int argc, char *argv[])

{

entry entries[MAX_ENTRIES];

register int x,m=0;

int cl;

printf("Content-type:

text/html%c%c",10,10);

if(strcmp(getenv("REQUEST_METHOD"),"POST"))

{ printf("This

script should be referenced with a METHOD of POST.\n");

printf("If you don't

understand this, see this "); printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">

forms overview</A>.%c",10);

exit(1);

} if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded"))

{printf("This script

can only be used to decode form results. \n");




Содержание  Назад  Вперед