,,,
4.1 WWW (World Wide Web)
4.2 CGI
4.2.1
4.2.2
4.2.3
4.2.4
4.3 cgi-
GET POST
4.3.1 GET
4.3.2 POST
4.4 cgi-
WWW- WWW, HTML /++.
, , . WWW, HTML-, . HTML-:
HTML-, - HTML- . , . HTML- cgi-. , .
, WWW.
WWW HTML-, .
, , . , SQL-, , . CGI(Common Gateway Interface).
Common Gateway Interface (CGI) WWW .
:
4-1. .
HTML-, . HTML .
HTML, , 1 . 4.
, , HTML, .. cgi-.
"-" , HTTP WWW . , - , . HTTP (. .3) , , (URI-Uniform Resource Identifier), HTTP-. , POST GET. POST , , , , . GET , HTTP .
WWW- NCSA CGI-, () :
CGI 4 .
4-2. CGI-.
:
:
SERVER_SOFTWARE WWW (/)
SERVER_NAME , WWW , IP URL.
GATEWAY_INERFACE CGI(CGI/)
cgi-.
CONTENT_LENGTH .
CONTENT_TYPE , HTTP POST PUT, .
SERVER_PROTOCOL (/).
SERVER_PORT , .
REQUEST_METHOD , "POST","GET","HEAD" ..
PATH_INFO cgi-
PATH_TRANSLATED cgi-, PATH_INFO.
SCRIPT_NAME , URL.
QUERY_STRING "?" URL . .
REMOTE_HOST , . REMOTE_ADDRESS.
REMOTE_ADDRESS IP
AUTH_TYPE WWW- ( ) cgi- , .
REMOTE_USER .
REMOTE_IDENT , ( RFC 931)
HTTP_ACCEPT MIME . HTTP (/,/ ..)
HTTP_USER_AGENT .
GI - . , cgi-, , . cgi- . , cgi- HTTP .
cgi-,
. cgi-, CGI
, nph-.
cgi- .
cgi-
CR(0x10).
, . , CGI :
Content-type
MIME
: Content-type: text/html <CR><CR> , - HTML
Location
, ,
URL, . , , .
: Location: http://host/file.txt , WWW file.txt, . cgi- gopher , gopher://gopher.ncsa.uiuc.edu/. :
Location: gopher://gopher.ncsa.uiuc.edu/
*Status
HTTP/1.0 -, :
nnn xxxxx
: nnn - 3-
-
: HTTP/1.0 200 OK
Server: NCSA/1.0a6
Content-type: text/plain
< >
, .
POST HTTP . .
cgi- :
name=value&name1=value1&...&nameN=valueN
name - ,
value - ,
N -
CONTENT_LENGTH . cgi- CONTENT_TYPE ( ). CONTENT_LENGTH , cgi- . CONTENT_LENGTH CONTENT_TYPE , cgi-. , FORM - METHOD="POST" firm=&price=100023, CONTENT_LENGTH 21 CONTENT_TYPE application/x-www-form-urlencoded, .
GET, URL.
..
http://host/cgi-bin/script?name1=value1&name2=value2
QUERY_STRING
name1=value1&name2=value2
GI- :
, ( HTTP URL ) Bourne shell , cgi- .
GET POST, cgi- .
, . , , POST GET. REQUEST_METHOD . "-" , , , cgi-. , , cgi-, ( , , ..).
cgi- HTML- ( ). , .
cgi-
:
Content-type: text/html ( CR)
HTML.
D NCSA.
:
post-query - POST
query - GET
util.c - (
query post-query).
HTML query.
<HTML>
<HEAD>
<TITLE> CGI</TITLE>
</HEAD>
<BODY>
<FORM ACTION="http://iceman.cnit.nsu.ru/cgi-bin/post-query"
METHOD="POST">
<B> <I>( )</I>:</B>
<INPUT name=RealName type=text size=40 maxlength=60 value="
"><P>
: <INPUT name=Sex type=Radio value="" CHECKED>-
<INPUT name=Sex type=Radio
value="">-<P>
<INPUT name=Submit type=submit value="
"><BR>
<INPUT name=Reset type=reset value="">
</FORM>
</BODY>
</HTML>
" " WWW
(
"+",
128 "%"
( "" %8)).
:
RealName=%CF%E5%F2%F0%EE%E2+%C8%E2%E0%ED+%D1%E8%E4%EE%F0
%EE%E2%E8%F7&Sex=%CC%F3%E6%F1%EA%EE%E9&Submit=%CF%EE%F1
%EB%E0%F2%FC+%E7%E0%EF%F0%EE%F1
post-query :
argc = 0. argv =
SERVER_SOFTWARE = NCSA/1.5.1
SERVER_NAME = iceman.cnit.nsu.ru
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");
exit(1);
}
cl =
atoi(getenv("CONTENT_LENGTH"));
for(x=0;cl &&
(!feof(stdin));x++)
{m=x;entries[x].val =
fmakeword(stdin,'&',&cl); plustospace(entries[x].val);
unescape_url(entries[x].val);
entries[x].name =
makeword(entries[x].val,'=');
}
printf("<H1>Query
Results</H1>");
printf("You
submitted the following name/value pairs:<p>%c",10);
printf("<ul>%c",10);
for(x=0; x <= m;
x++)
printf("<li>
<code>%s = %s</code>%c",entries[x].name, entries[x].val,10);
printf("</ul>%c",10);
}
, post-query ,
. ,
, ..
"+"
.
post-query
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];
word[x] = '\0';
if(line[x]) ++x;
y=0;
while(line[y++] =
line[x++]);
return word;
}
char *fmakeword(FILE
*f, char stop, int *cl) {
/*
, "-" stop,
f cl.
*/
int wsize;
char *word;
int ll;
wsize = 102400;
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)
|| (feof(f)) || (!(*cl))) {
if(word[ll] != stop)
ll++;
word[ll] = '\0';
return word;
}
++ll;
}
}
char x2c(char
*what) {
/*
*/
register char digit;
digit = (what[0] >=
'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
digit *= 16;
digit += (what[1] >=
'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
return(digit);
}
void unescape_url(char
*url) {
register int x,y;
for(x=0,y=0;url[y];++x,++y)
{
if((url[x] = url[y]) ==
'%') {
url[x] =
x2c(&url[y+1]);
y+=2;
}
}
url[x] = '\0';
}
void plustospace(char
*str) {
/*
"+" ""*/
register int x;
for(x=0;str[x];x++)
if(str[x] == '+') str[x] = ' ';
}
GET , POST query. ACTION METHOD FORM.
<FORM action="http://iceman.cnit.nsu.ru/cgi-bin/query" METHOD=GET>
:
argc = 0. argv is =
SERVER_SOFTWARE = NCSA/1.5.1
SERVER_NAME = iceman.cnit.nsu.ru
GATEWAY_INTERFACE = CGI/1.1
SERVER_PROTOCOL = HTTP/1.0
SERVER_PORT = 80
REQUEST_METHOD = GET
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
PATH_INFO =
PATH_TRANSLATED =
SCRIPT_NAME = /cgi-bin/test-cgi
QUERY_STRING = RealName=%CF%E5%F2%F0%EE%E2+%C8%E2%E0%ED+%D1%E8
%E4%EE%F0%EE%E2%E8%F7&Sex=%CC%F3%E6%F1%EA%EE%E9&Submit=%CF%EE
%F1%EB%E0%F2%FC+%E7%E0%EF%F0%EE%F1
REMOTE_HOST = fwa.cnit.nsu.ru
REMOTE_ADDR = 193.124.209.74
REMOTE_USER =
AUTH_TYPE =
CONTENT_TYPE =
CONTENT_LENGTH =
, QUERY_STRING.
query post-query.
<FORM >...</FORM>
: .
:
: !
.
<INPUT>
: .
:
TYPE - .
NAME - .
VALUE -
.
SRC - URI .
IMAGE.
[CHECKED] - CHECKBOX.
SIZE - .
[MAXLENGTH] - ,
.
[ALIGN] -
[DISABLED] - "read only" -
. .
[ERROR] - , ,
.
<TEXTAREA >...</TEXTAREA>
: . .
:
NAME - .
.
ROWS - .
COLS - .
[VALUE] - .
[DISABLED] - "read only" -
. .
[ERROR] - , ,
.
<SELECT >
<OPTION > 1
...
<OPTION > N
</SELECT>
: ().
:
NAME - .
.
[SIZE] - .
[MULTIPLE] - .
[DISABLED] - "read only" -
.
.
<OPTION >
: <SELECT> .
:
SELECTED -
VALUE -
: [ ]
4.1 WWW (World Wide Web) 4.2 CGI 4.2.1 4.2.2 4.2.3 4.2.4 4.3
Copyright (c) 2024 Stud-Baza.ru , , , .