There are so many clients and servers exist in the word wide web. Today they are all connected together in a network which is called WWW network. They are connected use wires or wireless devices such as WIFI route. When you use your client such as iPhone to browse a page in the web. Your safari browser will send a request to the HTTP web server. After the HTTP web server receive your request, it will call back-end program to perform business logic and then return the result back to your client. Then your client (safari browser) will render the response data to you in the iPhone screen. This is just an example process of client server interaction mode.
HTTP is the abbreviation of Hypertext Transfer Protocol. It is used for web client and server to communicate. It is stateless that means it dose not maintain the communication state between the client and server. The client send the request and the server response to the client, after that the connection disconnected. If the client request again, the server will not remember that the client has do this before. It will treat the request from the same client as a new one. The advantage of this design is that the server can serve more clients at the same time.
A client can use a number of methods to make the HTTP request. Each of these methods will let the server to perform a special action. Below table will list the methods and its purpose.
- POST : Ask server to receive the data posted by the client. We always use html form to post data to the server.
- PUT : Just like POST method, you can also use PUT to post data to the server. But the difference is that PUT can not only post data but also update the data posted before. With PUT method you can replaces all existing data using the updated content.
- CONNECT : This is a reserve method. It is used to tell the server to create a tunnel between client and the server.
- DELETE : Tell the server to delete some web resources.
- HEAD : This method like Get method, the difference is that it only require the http headers back do not need return the http body.
- OPTIONS :This method tell server to list all the communication options for the request url.The syntax is :
OPTIONS /welcome.html HTTP/1.2
OPTIONS * HTTP/1.2
asterisk(*) means return the communication options for the entire server. Below is the response data example.
HTTP/1.1 200 OK
Allow: OPTIONS, GET, HEAD, POST
Date: Thu, 13 Oct 2016 11:45:00 GMT
Server: EOS (lax004/2813)
Expires: Thu, 20 Oct 2016 11:45:00 GMT
GET VS POST
Get and POST are two mainly used HTTP methods. They are used in different use cases.
Get method is used when you do not need to submit large amount of data. You can submit data by using this method also, but the submitted data length is limited to 2000 characters by default. Below is just a picture of the URL for a Get method.
All the data send to the web server is stored in the request header. Because your submitted parameter data is in the url, so it is not secure. But you can easily reuse the url to get the web page again.
POST method is used when you need to submit massive amount of data. All the data send to the server is stored in the request body other than the header. The submitted data is secure because you can not see the data in the post url. But this also make it unreachable by simply copy and paste the request url in your web browser. Below is just a POST request example.