Introduction HTTP:
It is designed to enable communications between clients and servers.HTTP works as a request-response protocol between a client and server. A web browser may be the client, and an application on a computer that hosts a web site may be the server.
Block Diagram of HTTP:
HTTP Request Methods:
Two commonly used methods for a request-response between a client and server are:
1 GET
2 POST
Action Attribute:
This attribute is used to specify the URL of the server page to which we want to send our form data.
Syntax:
<form name="myform" action="user.aspx">
i. get:-
In this method, we dont have security for our data and only limited data can be sent to the server page. This is the default method of the form. It can carry raw data from client to server
(rawdata ==> the data which is understandable to user)
Syntax:
<form action="page.py" method="get">
When to use GET?
Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also has limits on the amount of information to send. The limitation is about 2048 characters. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. GET may be used for sending non-sensitive data.
Note: GET should NEVER be used for sending passwords or other sensitive information!
Example:1
<body>
<form action="nit.html" method="get" name='myform'>
<label>User Name:</label> <br/>
<input type='text' name="user"><br/>
<label>Password:</label> <br/>
<input type="password" name="pass"><br/>
<input type="Submit" value="Sign-In">
<input type="reset" value="Cancel">
</form>
</body>
Some other notes on GET requests:
1 GET requests can be cached
2 GET requests remain in the browser history
3 GET requests can be bookmarked
4 GET requests should never be used when dealing with sensitive data
5 GET requests have length restrictions
The POST Method
In this method, we have security for our data and we can send bulk of data to the server. It can carry encrypted data from client to server page. (Encrypted means machine understandable format).
Syntax:
<form method="post">
When to use POST?
Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send. Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to server.
Example:
<body>
<form action="nit.html" method="post" name='myform'>
<label>User Name:</label> <br/>
<input type='text' name="user"><br/>
<label>Password:</label> <br/>
<input type="password" name="pass"><br/>
<input type="Submit" value="Sign-In">
<input type="reset" value="Cancel">
</form>
</body>
1 POST requests are never cached
2 POST requests do not remain in the browser history
3 POST requests cannot be bookmarked
4 POST requests have no restrictions on data length
Difference between GETand POST:
GET POST
Data is visible on URL address Not visible post information
Unsecured highly secured
Excellent Peformance Good Performance
Transfer limited amount of data TransferHugeAmountOfData
Unable to Upload file We can Upload files
Can be cached Not cached
HTTP Status Messages
1xx: Information
Message: Description:
100 Continue The server has received the request headers, and the client should proceed to send the request body.
101 Switching Protocols The requester has asked the server to switch protocols.
2xx: Successful
Message: Description:
200 OK The request is OK (this is the standard response for successful (HTTP requests)
201 Created The request has been fulfilled, and a new resource is created.
202 Accepted The request has been accepted for processing, but the processing has not been completed
3xx: Redirection
Message: Description:
300 Multiple Choices A link list. The user can select a link and go to that location.
301 Moved Permanently The requested page has moved to a newURL
302 Found The requested page has moved temporarily to a new URL
303 See Other The requested page can be found under a different URL
4xx: Client Error
Message: Description:
400 Bad Request The request cannot be fulfilled due to bad syntax
401 Unauthorized The request was a legal request,but the server is refusing to respond to it.
404 Not Found The requested page could not be found but may be available again in the future.
5xx: Server Error
Message: Description:
500 Internal Server Error A generic error message, given when no more specific message is suitable.
502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server
503 Service Unavailable The server is currently unavailable (overloaded or down)
1xx ==>199 ==> Information Related Messages
2xx==>299 ==> Successful Messages
3xx==>399 ==> Redirection Messages
4xx==>499 ==> Client Side Messages
5xx==>599 ==>Server Side Messages