This is a practical tutorial that will give you a deeper understanding of the HTTP protocol, and therefore requires a certain HTTP base.
Agreement: A provision that specifies how you should do it, such as the Internet Protocol that specifies how the browser should parse the HTML,CSS,JS. HTTP, however, specifies how the client can transfer data to and from the server, simply because we have to write it in its format.
A few days ago spent a bit of time to learn the HTTP protocol, but I think the light know not ah, but also to practice, now my Learning method is: either learn, or do not learn, learn to learn, of course, not really, but at least understand what it is, how to use, how better to use .... Unless this thing spent a long time did not understand, first put, because before learning things is always East point of Western Point, still do not understand it ran to learn other, finally found still have to go back to learn, so instead of wasting a lot of time, finally nothing learned, for HTTP before it is not the case, But as time goes by, it is really necessary to learn it, so in order to better understand the HTTP protocol, here in PHP to practice. After all, to play with the HTTP or to use a bit of back-end things, although the backend understanding is not a lot, but to learn this enough.
Tools to use:
1.php environment We need to exchange data with the client.
2.telnet telnet: Can be used to connect to a remote server.
Win7 default does not turn on Telnet, if open can read this article: Win7 How to resolve a scenario where Telnet is not an internal or external command
cmd input telnet IP 80 back to the native IP can be viewed via ipconfig
Telnet 192.168.1.100 80
We also need to go into echo mode. Press Ctrl +]
Press ENTER again to OK.
We can then write the HTTP format.
Test get first.
Input: GET/file path http/1.1 Enter this carriage return indicates the end of the request line
Host:ip Address Enter this enter to indicate the end of this request header
Enter this enter to indicate the end of the input, send the request.
get/index.php http/1.1
host:127.0.0.1
index.php
<?php
Echo ' Hello HTTP ';
?>
The returned data
Request Line
GET: Request method
./index.php: Request Path
Http/1.1:http version
Request Header
Host:127.0.0.1:ip Address
Get no request body
As we can see from this example, HTTP does not have to have a browser, but sending HTTP must be in its format.
You can see their general execution process:
Establish connection-response connection-close connection
The original browser to help us do a lot of things, such as host, browser through our URL resolution, HTTP version according to the browser itself, the path is also resolved through the URL.
Post test:
post/index.php http/1.1
host:127.0.0.1
content-type:application/x-www-form-urlencoded
Content-length:10
Name=rrraa
This must be written on content-length and Content-type or not sent successfully.
Content-length: The client will receive the length of the data according to this, beyond whatever.
Content-type: Tells the client what this data type is.
index.php
<?php
$str = Implode ($_post, "\ n"); Receive data
Print_r ($STR); Response data
?>
Through the head method without getting the content of the case, check the server a file exists, the previous interview also asked the question, then did not answer.
head/index.php http/1.1
host:127.0.0.1
Accept: *
You must add accept or you will get the content, just like the Get method.
This allows us to determine whether a file exists and is modified without obtaining the contents of the file by means of a status code.
We visit a fake path to see what the situation is.
404, it's exactly what we want.
The practice of using these HTTP protocols is really good, and learning a lot of new things, if only to see the theory is not.
You can also try the other.
Use Telnet to practice the HTTP protocol.