Вы находитесь на странице: 1из 10

FMA 3: DESIGNING CS APPLICATION

HTTP (Hypertext Transfer Protocol)


HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files (text, graphic images, sound, video, and other multimedia files) on the World Wide Web. As soon as a Web user opens their Web browser, the user is indirectly making use of HTTP. HTTP is an application protocol that runs on top of the TCP/IP suite of protocols (the foundation protocols for the Internet). A browser is works as an HTTP client because it sends requests to an HTTP server which is called Web server. The Web Server then sends responses back to the client. The standard and default port for HTTP servers to listen on is 80 but it can be changed to any other port like 8080 etc. There are three important things about HTTP of which you should be aware: a. HTTP is connectionless: After a request is made, the client disconnects from the server and waits for a response. The server must re-establish the connection after it process the request. b. HTTP is media independent: Any type of data can be sent by HTTP as long as both the client and server know how to handle the data content. How content is handled is determined by the MIME specification. c. HTTP is stateless: This is a direct result of HTTP's being connectionless. The server and client are aware of each other only during a request. Afterwards, each forgets the other. For this reason neither the client nor the browser can retain information between different requests across the web pages. Figure 1: shows where HTTP Protocol fits in communication:

GIOVANNE P. LAPAY FMA 3. Designing CS Application

HTTP METHODS
The GET Method The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process. A conditional GET method requests that the identified resource be transferred only if it has been modified since the date given by the If-Modified-Since header. The conditional GET method is intended to reduce network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring unnecessary data. The GET method can also be used to submit forms. The form data is URL-encoded and appended to the request URI The HEAD Method A HEAD request is just like a GET request, except it asks the server to return the response headers only, and not the actual resource (i.e. no message body). This is useful to check characteristics of a resource without actually downloading it, thus saving bandwidth. Use HEAD when you don't actually need a file's contents. The response to a HEAD request must never contain a message body, just the status line and headers. The POST Method A POST request is used to send data to the server to be processed in some way, like by a CGI script. A POST request is different from a GET request in the following ways: There's a block of data sent with the request, in the message body. There are usually extra headers to describe this message body, like Content-Type: and Content-Length: The request URI is not a resource to retrieve; it's usually a program to handle the data you're sending. The HTTP response is normally program output, not a static file. The most common use of POST, by far, is to submit HTML form data to CGI scripts. In this case, the Content-Type: header is usually application/x-www-form-urlencoded, and the Content-Length: header gives the length of the URL-encoded form data. The CGI script receives the message body through STDIN, and decodes it.

GIOVANNE P. LAPAY FMA 3. Designing CS Application

Here's a typical form submission, using POST:POST /path/script.cgi HTTP/1.0 From: frog@jmarshall.com User-Agent: HTTPTool/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 32 home=Mosby&favorite+flavor=flies GET vs POST Methods If you were writing a CGI script directly i.e. not using PHP, but Perl, Shell, C, or antoher language you would have to pay attention to where you get the user's value/variable combinations. In the case of GET you would use the QUERY_STRING environment variable and in the case of POST you would use the CONTENT_LENGTH environment variable to control your iteration as you parsed for special characters to extract a variable and its value. POST Method: Query length can be unlimited (unlike in GET) Is used to send a chunk of data to the server to be processed. You can send entire files using post. Your form data is attached to the end of the POST request (as opposed to the URL).

Not as quick and easy as using GET, but more versatile (provided that you are writing the CGI directly). GET Method : Your entire form submission can be encapsulated in one URL, like a hyperlink so can store a query by a just a URL. You can access the CGI program with a query without using a form. Fully includes it in the URL: http://myhost.com/mypath/myscript.cgi?name1=value1&name2=value2. Is how your browser downloads most files. Don't use GET if you want to log each request. Is used to get a file or other resource.

GIOVANNE P. LAPAY FMA 3. Designing CS Application

Figure 2: Communication between browser and server The navigator makes a HTTP request The server processes the request then sends a HTTP response In reality, the communication is conducted in more stages if you consider the processing of the request by the server. HTTP Request A HTTP request is a collection of lines sent to the server by the browser. It includes: A request line: This is a line specifying the type of document requested, the method which must be applied, and the version of the protocol used. The line is made up of three elements which must be separated by a space: The method The URL The version of the protocol used by the client (generally HTTP/1.0) The request header fields: This is a collection of optional lines allowing additional information about the request and/or the client to be given (browser, operating system, etc.). Each of these lines is composed of a name describing the header type, followed by a colon (:) and the value of the header The body of the request: This is a collection of optional lines which must be separated from preceding lines by an empty line and for example allowing data to be sent by a POST command during the sending of data to the server using a form

GIOVANNE P. LAPAY FMA 3. Designing CS Application

COMMANDS
Command GET HEAD POST PUT DELETE Description Request for the resource located at the specified URL Request for the header of the resource located at the specified URL Sends data to the program located at the specified URL Sends data to the specified URL Deletes the resource located at the specified URL

HEADERS
Header name Accept Accept-Charset Accept-Encoding Accept-Language Authorization Content-Encoding Content-Language Content-Length Content-Type Date Forwarded From From Link Orig-URL Referer User-Agent Description Type of content accepted by the browser (for example text/html). Character set expected by the browser Data coding accepted by the browser Language expected by the browser (English by default) Identification of the browser to the server Type of coding for the body of the request Type of language in the body of the request Length of the body of the request: Type of content of the body of the request (for example text/html). Date data transfer starts. Used by intermediary machines between the browser and server Allows the client email address to be specified Makes it possible to specify that the document must be sent if it has been modified since a certain date. Link between two URLs URL from which the request originated Link URL from which the request has been made String giving information about the client, such as the name and version of the browser and the operating system

GIOVANNE P. LAPAY FMA 3. Designing CS Application

HTTP STATUS CODES

GIOVANNE P. LAPAY FMA 3. Designing CS Application

GIOVANNE P. LAPAY FMA 3. Designing CS Application

Figures 4: Using the telnet a. Connecting to TELNET

GIOVANNE P. LAPAY FMA 3. Designing CS Application

b. Example of error in GET command

c. Example of error in Request

GIOVANNE P. LAPAY FMA 3. Designing CS Application

a. Successful Connection

Reference:
http://searchwindevelopment.techtarget.com/definition/HTTP http://www.tutorialspoint.com/http/http_methods.htm http://en.kioskea.net/contents/internet/http.php3

GIOVANNE P. LAPAY FMA 3. Designing CS Application

Вам также может понравиться