The HTTP protocol can be likened to a conversation based on a series of questions and answers, which we refer to respectively as HTTPrequests and HTTP responses.
The contents of HTTP requests and responses are easy to read and understand, being near to plain English in their syntax.
This section examines the structure of these requests and responses, along with a few examples of the sorts of data they may contain.
The HTTP Request
After opening a connection to the intended server, the HTTP client transmits a request in the following format:
The opening line is generally split into three parts; the name of the method, the path to the required server resource, and the HTTP version being used. A typical opening line might read:
GET /sams/testpage.html HTTP/1.0
In this line we are telling the server that we are sending an HTTP request of type GET (explained more fully in the next section), we are sending this using HTTP version 1.0, and the server resource we require (including its local path) is
Header lines are used to send information about the request, or about the data being sent in the message body. One parameter andvalue pair is sent per line, the parameter and value being separated by a colon. Here’s an example:
User-Agent: [name of program sending request]
For instance, Internet Explorer v5.5 offers something like the following:
User-agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
A further example of a common request header is the Accept: header, which states what sort(s) of information will be found acceptable as a response from the server:
Accept: text/plain, text/html
By issuing the header in the preceding example, the request is informing the server that the sending application can accept either plain text or HTML responses (that is, it is not equipped to deal with, say, an audio or video file).
The HTTP Response
In answer to such a request, the server typically issues an HTTP response, the first line of which is often referred to as the status line. In that line the server echoes the HTTP version and gives a response status code (which is a three-digit integer) and a short message known as a reason phrase. Here ’s an example HTTP response:
HTTP/1.0 200 OK
The response status code and reason phrase are essentially intended as machine-and human-readable versions of the same message, though the reason phrase may actually vary a little from server to server. Table lists some examples of common status codes and reason phrases. The first digit of the status code usually gives some clue about the nature of the message:
TABLE Some Commonly Encountered HTTP Response Status Codes
The response may also contain header lines each containing a header and value pair similar to those of the HTTP request but generally containing information about the server and/or the resource being returned:
Last-Modified: Fri, 24 Dec 1999 13:33:59 GMT
AJAX Related Interview Questions
|XML Interview Questions||HTML Interview Questions|
|Java Script Interview Questions||Android Interview Questions|
|CSS Interview Questions||Web Developer Guide Interview Questions|
|XSLT Interview Questions||Java XML Interview Questions|
|XML DOM Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.