HTTP request and response messages
HTTP request message
By decrypting the URL, once the Web server and the file name are known, the browser creates an HTTP request message based on it. Since the format of the actual request message has been decided in advance, the browser creates a request message according to this format.
- Request message
<Method> <Blank> <URL> <Blank> <HTTP version> …… ①
<Field name>: <Field value> …… ②
<Message body> …… ③
①: This first line is called the request line, and you can roughly understand the contents of the request with this one line.
②: This part is called a message header, and one header field is described in one line. This represents value-added information about the request. The number of lines depends on the situation, and up to blank lines are considered as message headers.
③: The content of the message body is the data to be sent from the client to the server, and the data when the data entered in the form is sent to the Web server by the POST method.
- Response message
<HTTP version> <Blank> <Status code> <Blank> <Response phrase> …… ①
<Field name>: <Field value>
<Message body> …… ②
①: This line is called the status line, and a short description indicating the content of the status code is described in the response phrase.
②: The content of the message body is the data sent from the server to the client. The data read from the file and the data output by the CGI application are described. Treat these message bodies as binary data.
First, write the request line on the first line of the request message. The method to be described at the top is for requesting the Web browser how to want the Web server to do what, but since there are many kinds of methods, you must decide which method to write. Normally, when inputting a URL in the URL description field of the browser and assuming that the page is displayed as it is, clicking the hyperlink embedded in the Web page, or writing data in the form When you press the send button, the type of method will change. If you enter a URL in the URL field, use the GET method as well, even if you click on the hyperlink, that page will be displayed as it is. In the case of the form, since it specifies which method is used to send the request in the HTML source code of the form part, we will use GET and POST differently each time. Since the amount of data that can be sent with GET is as small as several hundred bytes, if the data to be entered in the field exceeds it, you must use the POST method. After writing the method, leave a blank, then write the URI. It is usual to describe the path name of a file or program in the URI part in the following format. / <Directory name> / … … / / <file name> Since the normal path name is embedded in the URL, it takes out the path name from the URL and copies it. Then, at the end of the first line, to indicate the version specification of HTTP which version of the message is described, the version number is to be described. This concludes the first line.
Message header and message body
From the second line it is followed by a line called message header. The first line specifies the contents of the request, and the second header contains additional necessary information in the message header. A number of items such as date, type of data handled by client side, language, compression format, expiration date of client and server, last update date and time are specified in the specifications. In order to understand the meaning that detailed information accurately, detailed knowledge of HTTP becomes necessary.
Table 1: Major header fields used in HTTP
- General header: header field used for both request and response
|Represents the date and time when the request or response was created
|It represents the communication option, such as whether to allow data caching
|Information for controlling the cache
|Specification of communication options such as continuation of TCP connection or disconnection after response transmission
|Represents the encoding method of the message body
|Record the proxy and gateway that passed through
- Request header: header field used as additional information of the request
|Data for user authentication
|Request sender’s e-mail address
|When you want to execute a request only if the information has been updated since a certain date and time, when you want to execute the request as a field value, specify the date and time as the field value. It is usually used when you want to receive new information when it gets old as compared with information cached on the client side
|Represents the URI that became the link source, for example, when following the hyperlink and reading the next page
|Information on the name and version of the client software
|The type of data that the client can receive as Content-Type. Expressed by data type of MINE specification
|Character code set that can be received by the client side
|Encoding method that the client can receive as Content-Encoding. It represents the format of compression of ordinary data
|The type of language that the client can receive. Japanese is ja, English is en
|IP address and port number of the server receiving the request
The contents described in the message header differ depending on the browser type, version, setting, and so on. After describing the message header, add a blank line after that and describe the body of the transmission data called the message body. However, when the method is GET, it is unnecessary to describe the transmission data, which is the transmission data itself, since the Web server can determine what to do with only the method and URI. The message ends with message header. When the method is POST, describe the data etc. entered in the form in the part of the message body. This completes the creation of the request message.
HTTP response message
When sending an HTTP request message to the web server, an HTTP response message is returned. The basic format of the response message format is the same as the request message. However, if the first line is wrong and the response message, the status code and the response phrase indicating the execution result of whether the request message was normally ended or an error occurred will be described in the first line It is. The status code is written in numbers, and mainly has the purpose of informing the program etc. of the execution result. In addition, the response phrase describes its details in sentence format.
- HTTP status code overview
|Notify the progress of processing etc.
|It signifies that some other action is required
|Client side error
|Server side error
When the response message comes back, it retrieves the data from it and displays it on the web browser. If there are other elements such as images, control information called a tag representing an image file is embedded in the response message, so if the browser finds the tag and finds a tag meaning to paste the image, Leave room for images there. Then, once again accessing the Web server, the image file indicated by the tag is read to the Web server and displayed in the vacant space. In that case, as well as reading the sentence file, create a request message with the name of the image file in the URI part and send it to the web server. Since only one URI is specified in the request message, only one file can be read at a time, one at a time. For example, if three images are stuck in one sentence, it will send a request message to the Web server four times in total, with a request to read the sentence file and a request to read the image file. The browser judges and reads necessary files, displays them on the screen after reading out the layout. In this way we will control the overall operation. The Web server does not assume such a role, simply to return a single response for one request to realize the behavior of the browser. This is the whole of the interaction between the browser and the Web server.
- Response header: header field used as additional information of response
|It represents the exact location of the information. Used to notify the position of information with an absolute name, such as when the URI of the request is specified by relative name etc.
|Information on the name and version of the server software
|When access to the requested information is restricted, data for user authentication (such as challenge) is sent back
|If there is a Range specification requesting only part of the data, it notifies the client whether the server has the function
- Entity header: header field used as an additional function of entity (message body)
|Represents methods available for the specified URI
|In the case where encoding processing such as compression is applied to the message body, this method is expressed
|Represents the length of the message body
|Indicates what kind of data the message body is, its kind. Represents the type of data with the data type defined in the MINE specification
|Represents the expiration date of the message body
|Last update date of information
|Represents the language of the message body. For Japanese, ja, English for en
|Where the message body was located in the server, its location in URI
|When a part, not the entire data, is requested, it indicates the range of data included in the message body
|In the update process etc., there are cases where update data based on the response of the previous request is transmitted with the next request, but in that case, the information used to associate the previous response with the next request. In the previous response, if the server passes a unique value to the client by Etag and notifies the server of its value in the if-Match, if-None-March, if-Range field of the next request, the server last time It will recognize. The fields and roles that we call cookies are the same. Cookies are proprietary to NetScape, Etag is a standardized version of it