The contents of HTTP requests and responses!? Part 1

### Overview

What is the HTTP in the previous article,

I mainly wrote about the difference between GET and POST is an HTTP method.

About the actual contents of the HTTP communication that had previously also mentioned in the part of the POST this time,

specifically, I think let's write about the contents of the request and response.

### Each of the message configuration

HTTP communication wrote last time and are made up in the request and response.

We send a request, the server is that that will return a response,

you have to display the desired page.

So, do you have happened to the contents of the request and response?

1. let's take a look from its configuration.

### Request message

Request message is composed of the following elements.

Request line

message body

As each kind of thing to do will be briefly described,

Request line

whether the client would like to any request, information is stored that.

GET or POST are also described herein.

information needed to actually request has been stored.

Language and you are using, whether you're using any browser, data that is sent to is such as whether there is a capacity of how much.

Message body

data when transmitting the actual data is stored.

When you send the data in the GET request, nothing is stored in the message body so send to grant the data as URL, which also wrote the last time.

When you send the data in the POST request, the data to be transmitted will be described in the message body.

### Response message

Response message is composed of the following elements.

Status line

message body

Here even if each is briefly described what things of,

Status line

or the result of a request from the client was how, information is stored that.

By code (three digits), which is referred to as the status code represents the result of the request.

information necessary for the response has been stored.

And server information, is like programming language that is used on the server.

Message body

actually content to be a response in response to the client's request has been stored.

If the web server, you will be HTML page that has received the request is stored in the message body.

The configuration of each of the messages are easily made as described above.

Let's take a look a little more what specific kind of information is stored.

### The contents of the request message

Request message, wrote and composed of a request line header message body.

Because I think that character alone is difficult to understand, we will look at the inside of each of the elements from the actual content of the request.

Request line

you try to send a GET request to the First actually google.

# curl -v -X GET http://www.google.com


Since this time is the focus on to see the middle, it does not write to the description of the fine command.

Please continue reading with the feeling that said that I can see do it this way.

I think that actually do good to get to copy and paste the command that is written to when to check on their own.

A description of the command that we used in this and subsequent articles I will write.

When you run the above command, it will return a very long response.

Since the very things and put all, here we put those to pick up part of the purpose.

Among the send request message, the request line is the following.

GET/HTTP/1.1


To explain what is entered,

"GET" I think whether you can see by now, is the HTTP method that was used to request.

"/" Represents the location of the page called "I have been taking a page from here."

If the designated specifically, this part will be the case most of the "/".

"HTTP/1.1" is the HTTP version information to be used in the request.

Since in some cases the version is different from the communication does not work, tells that "Let's communication in this version" when making a request to the server.

Next, the header is the following.

Host: 172.217.161.238
User-Agent: curl/7.54.0
Accept: */*


This time sent from the command, such as the browser of the information is not written.

As the information that is stored this time,

"Host: 172.217.161.238" is the information of the target server to send the request.

"User-Agent: curl/7.54.0" because that sent the request from this command, are stored command and version information that was used.

In fact send a request from a web browser, it will be stored browser information in this header.

"Accept: / " will not store the information of the media that can be accepted in the response, the information of priority.

Of this "*/*" will be in the sense that it may be in any media.

More specifically, it is also possible to specify to send, such as in text or html format.

Header There are things in very many even than those described this time.

Because I think that anyone who wants to know more about the next page would be helpful, if you are interested here please visit.

Finally, the message body is, but this does not have to be too eye.

And say there is a little misleading, but the actual content that you have entered when you send the data is sent.

If the login screen, such as ID and password.

So, I think there is no need to see again.

If that you really want to check from the command can be confirmed as follows.

curl --trace-ascii - -X POST -d "{'data':'test'}" http://192.168.56.15:50080


Such as the destination of the IP address must be changed to suit your own environment, but

this command is a command to display the communication contents of the entire HTTP communication.
-d "{ 'data': ' test'} will have to specify the data to be sent in the POST.

When I want to run this command,

Note: Unnecessary use of -X or --request, POST is already inferred.
== Info: Rebuilt URL to: http://192.168.56.15:50080/
== Info:   Trying 192.168.56.15...
== Info: TCP_NODELAY set
== Info: Connected to 192.168.56.15 (192.168.56.15) port 50080 (#0)
=> Send header, 153 bytes (0x99)
0000: POST/HTTP/1.1
0011: Host: 192.168.56.15:50080
002c: User-Agent: curl/7.54.0
0045: Accept: */*
0052: Content-Length: 15
0066: Content-Type: application/x-www-form-urlencoded
0097:
=> Send data, 15 bytes (0xf)
0000: {'data':'test'}
== Info: upload completely sent off: 15 out of 15 bytes
== Info: HTTP 1.0, assume close after body
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.0 200 OK
<= Recv header, 35 bytes (0x23)
0000: Server: BaseHTTP/0.3 Python/2.7.5
<= Recv header, 37 bytes (0x25)
0000: Date: Fri, 15 Mar 2019 14:33:36 GMT
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 0 bytes (0x0)
== Info: Closing connection 0


Such content is output.

The part that it is possible to know what's contained in the message body in this

=> Send data, 15 bytes (0xf)
0000: {'data':'test'}


It is this part.

Here is { 'data': 'test' } that represents that it has sent the 15 bytes of data.

That is, the message body { 'data': 'test' } data that will be referred to is stored.

### ... I've longer only unexpectedly request

I was going to write the message of the request and response in one article, but

because I have longer only unexpectedly request,

the contents of the response message will continue to write in the next article.