JSP Summary one: HTTP protocol

Source: Internet
Author: User
Tags header port number

the HTTP protocol was invented by Tim Berners-lee, known as the web's father. The HTTP protocol is completely text-based. Browsers interact through HTTP protocol and server, and the default is port 80. You can also explicitly indicate the port number in the URL. For example: http://localhost:8080/index.html. HTTP protocol is a stateless protocol, and is not suitable for real-time access to data applications, because too much real-time client and server interaction will lead to frequent network communication and bandwidth constraints. The HTTP protocol also does not tell the server how the client's request was generated. This makes B/s more difficult to implement than C/S.

the
Browser has two main commands and server interactions, one called get, and the other is called post. Logically, a GET command is equivalent to a read operation, making a request to the server, and then getting the data, and the post command sends an instruction to the server to perform an action, potentially modifying some data on the server, and therefore irreversible. We want to prevent users from constantly refreshing the page raised by the Post command, usually a prompt dialog box to let users confirm that the operation is really necessary to do is a common method.

the format of the
get command: The request line, the request header, and the request body (optional).


get/index.html http/1.0


Host:www.gefionsoftware.com


user-agent:mozilla/4.5 [en] (winnt;i)


accept:image/gif, Image/jpeg, Image/pjpeg, image/ping,*/*


accept-language:en


accept-charset:iso-8859-1,*,utf-8


 


The above example, the first line is the request line, indicating the get command, the requested resource is index.html, and the protocol is HTTP1.0. All that follows is the request header, without the request body.


 


Server response format: status line, answer header, answer body (optional).


http/1.0 OK


Last-modified:mon, Dec 2001:23:26:42 GMT


Date:tue, 2002 20:52:40 GMT


status:200


content-type:text/html


servlet-engine:tomcat Web server/4.0.1


content-length:59


 





<body>





</body>





 


the first line is the status line, protocol + state value + status description. Then the answer header, and the last piece of HTML code is the answer body. We often see a response with a status value of 401, and representatives are not authorized.


If the answer body is more complex, it contains links to pictures or other resources. The client will automatically issue a GET command to obtain the related resources. Usually these actions are parallel, but each browser behaves differently: IE appears to be serial, and Firefox first displays the contents of the first answer body, showing the answer body of the embedded picture one at a while.


 

The
get command can also be coupled with request parameters. Request parameters can then follow the URL, such as:


http://localhost:8080/index.html?a=2&b=7? Start,& interval each parameter name and value pair. This approach is called a query string. Because?,=,& is used as a separator, other characters are sent using a URL encoding to avoid confusion. Welcome to network , Collection of this article [1] [2]

$False $


       can also send request parameters (the same format) as part of the request body, although this is usually the practice of post commands.
       Post command format:
Post forecast http/1.0
Host:www.gefionsoftware.com
user-agent:mozilla/4.5 [en] (WinNT; I)
Accept:image/gif, Image/jpeg, Image/pjpeg,image/png, */*
accept-language:en
Accept-charset: Iso-88569-1,*,utf-8
City=hermosa+beach&state=ca
 
       The forecast in the post line is the name of the action, followed by the protocol name. Note the last line of the query string, no? , and is embedded in the post body. Usually the post is triggered by the form form. For example, the above command corresponds to the form forms:
<form action: "/forecast" method= "POST"
       City: <input name= "City" type= "text"
       State: <input name= "state" type= " Text>
<p>
<input type= "SUBMIT"
</form>
       Note , where the first line adds a property method= "POST", and if not, the default is get. The other methods of the
HTTP protocol are five options,head,put,delete,trace. But these methods are rarely used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.