Saturday, January 11, 2014

2  Marks IP
36. What is meant by Stateless Connection?
When a web server receives a HTTP request from a web browser it evaluates the
request and returns the requested document, if it exists, and then breaks the HTTP connection.
This document is preceded by the response header, which has details about how to display the
document that will be sent by the server. Each time a request is made to the server, it is as if
there was no prior connection and each request can yield only a single document. This is
known as Stateless Connection.
37. Write a note on Environment variables.
In CGI, the server prepares the environment variables before it launches the CGI
script. These represent the current state of the server that is asking for the information. The
environment variables are not set from the command line but are created on the fly, and lasts
only until that particular script is finished. Each script gets its own unique set of variables and
multiple scripts can be executed at once, each in its own environment.
38. What are STDIN and STDOUT?
These are mnemonics for standard input and standard output, two predefined stream /
file handles. Each process already inherits these two handles already open. From the script's
point of view, STDIN is what comes from the browser via the server when the post method
is used, and the STDOUT is where it writes its output back to the browser. The script picks
up the environment variables and reads STDIN as appropriate. It then does whatever it was
designed to do and writes its output to STDOUT.
39. What are the two commonly used Request methods?
The request methods tell the script how it was invoked. Based on this information, the
script decides how to act. The request method is passed to the script using environment
variable called REQUEST- METHOD. The two most common request methods used are GET
and POST.
GET
GET is a request for data, the same method used for obtaining static documents. The GET
method sends request information as parameter tacked onto the end of the URL. These
parameters are passed to the CGI program in the environment variable QUERY-STRING.
E.g.: If the script is called myprog.exe and is invoked from a link with the form
<A HREF="cgi-bin/myprog.exe? lname=blow&fname=joe"> The REQUEST_METHOD
will be the string GET, and the QUERY_STRING will contain lname=blow & fname=joe.
A mandatory question mark separates the name of the script from the beginning of the
QUERY_STRING. If a slash is used instead of the question mark; the server passes the
information to script using the PATH_INFO variable instead of the QUERY_STRING
variable.
POST
POST operation occurs when the browser sends data from a fill-in form to the server.
With POST, the QUERY_STRING mayor may not be blank, depending on the server.
The data from a POSTed query gets passed from the server to the script using STDIN.
Because STDIN is a stream and the script needs to know how much valid data is waiting, the
server also supplies another variable, CONTENT_LENGTH, to indicate the size in bytes of the
incoming "data. The format for POSTed data is
Variable1=value1 & variable2=value2 &etc.
After the required data is available, the script executes and writes its output to the
STDOUT. The MIME code that the server sends to the browser indicates the type of the file
that is being sent. This information that precedes the file is usually called the header. Since the
script generates the output on the fly the server will not be able to create a header for that
information. Hence this information has to be supplied by the script itself. Failure will result in
the browser receiving information that it does not know how to display.
40. Explain about URL Encoding.
HTTP specification requires that the URL data should be encoded in such a way that it can
be used on almost any hardware and software platforms. Information specified in this way is
called URL encoded. If parameters are passed as a part of query string or path information,
they will take the form of ‘Name-Value’ pairs.
variablel=valuel&variable2=value2& so on for each variable defined in the form.
The variables or name value pairs are separated by '&'. Real ampersand is escaped -that
is, encoded as a two-digit hexadecimal value representing the character. Escaped characters
are indicated in URL-encoded string by the percent (%) sign. Blank spaces are replaced by
'+' sign. Before the script can deal with the data it has to parse and decode it. The script scans
through the string looking for an ampersand. When it is found the string is broken from that
point. The variable's name is every thing up to the equal sign in the string and the value is
every thing after the equal sign. The script continues to parse the original string for the next
ampersand, and so on until the original string is exhausted. After the variables are separated,
they are decoded as follows.
1. Replace all plus signs with blank spaces.
2. Replace all %## (Percent sign followed by two hexadecimal digits) with the
corresponding ASCII character.

Separate the name-value pairs from the URL and store the values separately.

No comments:

Post a Comment