Client is an end user and server is a computer program that provides services to client or user.
In order to interact in day to day life, we need a commom language.
In a similar way, a client and server interact using HTTP(Hyper Text Transfer Protocol).
HTTP is a Protocol(a standard way of communicating over a network), which runs above TCP/IP.
TCP/IP is responsible for routing your message properly from source to destination.
Now here the source and destination would be client/server.
Now a client sends request to server on HTTP request and the server responds to it on HTTP response.
What happens on entering a URL in your browser and click submit?
A HTTP request is being sent to web server, which is designed to handle HTTP request, to retrieve the particular web page.
Web-server responds with HTTP response containing the required web page.
HTTP request stream contains method name like GET,POST,etc, the page to access and form paraneters.
GET is mostly used to request for webpage, whereas POST in case of submitting form details(which need to be hidden).
Lets see the anatomy of GET,
Enter http://www.sun.com/ in your web browser, the generated HTTP request header would be as follows:
GET / HTTP/1.1Host: www.sun.com
Connection: closeUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)Accept-Encoding: gzipAccept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7Cache-Control: noAccept-Language: de,en;q=0.7,en-us;q=0.3
Here GET refer to request for a page.Host is your requested URLUser-Agent is your web browser detailsAccept-encoding refers to kind of Encoding your browser supportsAccept-Language refers to kind of language your brower supports
The server responds through HTTP response for the requested web page.
HTTP response header details as follows:
HTTP Status Code: HTTP/1.1 200 OK
Server: Sun-Java-System-Web-Server/6.1
Date: Tue, 27 May 2008 09:07:10 GMT
Content-type: text/html;charset=UTF-8 P3p: policyref="http://www.sun.com/p3p/Sun_P3P_Policy.xml", CP="CAO DSP COR CUR ADMa DEVa TAIa PSAa PSDa CONi TELi OUR SAMi PUBi IND PHY ONL PUR COM NAV INT DEM"
X-powered-by: Servlet/2.4,JSP/2.0
Connection: close
Here HTTP Status code specifies version type of HTTP.Content type specifies the type of data format being sent from server.
Now in order to see all Request and Response Header details. Visit http://web-sniffer.net/
Enter the requested URL and see the header level details.
For URL, https://69.46.17.169/servlet/redirect.srv/sruj/saorsbzq/snop/p1/"
Generated HTTP request line would be as follows:
GET /select/getDetails.jsp?name="hero"&dob="17061986" HTTP/1.1
so here,
HTTP method --> GET
The page to access--> /select/getDetails.jsp
Form paraneters--> name="hero"&dob="17061986"
Now for POST,
POST is having a message body.The form parameter mentioned above goes into a message body.
In GET, the data has been encoded in URL, whereas in POST, it has been encoded in message body.
Sometimes we need to hide the parameter passed to server due to security reasons. So make use of POST there.
GET is idempotent, means returning same webpage on each request.
GET is used for retrieving data and POST is used for storing, updation,etc of data.
Wednesday, May 28, 2008
How does a client and a server interacts?
Labels:
client,
client and server,
client-server model,
GET,
HTTP,
http request,
http response,
POST,
protocol,
server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment