HTTP protocol-get, post, put, delete

Source: Internet
Author: User
Tags getting started with php response code

HTTP protocol, a network in which file transfer follows the protocol. A stateless protocol, HTTP protocol server side does not establish a long-term communication connection with the browser side, that is, the service side can not identify the end of the request. After an HTTP communication is established, the server completes a request by transmitting the contents of the file to the browser-side receiver. Of course, a page, often composed of multiple HTTP requests, pictures, CSS and other resource requests ~ may be a page to make multiple HTTP requests after the results.

HTTP stateless, understood as: no matter which browse to Baidu to send requests, are the same results. Baidu server can not determine the two times before and after the request to Baidu is not the same client. (Of course, you can follow cookies, IP analysis to specific browsers and user behavior)


On my machine request Baidu https://www.baidu.com as shown in the picture, when the request www.baidu.com this URL, analysis to Baidu services under the corresponding resources, the same browser-side of the various background pictures, styles, Will initiate HTTP requests to get the corresponding file resources. including pictures, CSS style file information and the requested HTML file, the overall composition of the user's browser-side to see the state.




HTTP protocol, the successful launch of the request, first of all through the DNS domain name resolver, will www.baidu.com this domain name, resolved to the correct IP address of the server, the general situation does not specify the following specific resources, the browser will automatically locate the root directory "/" The next www.baidu.com pieced together into www.baidu.com/, www.baidu.com only DNS can resolve to the IP domain name, "/" is the location of the specified resources, the general root directory will default to the index file (of course, this random server configuration to make changes). In fact, in the browser directly enter the corresponding IP address, the request is the same. Because the essence of the server's last request is to locate it through IP.



HTTP protocol status Code, common should be 404 error, directly throw the page does not exist error. At that time actually in the browser work, 200 and 304 response code should be the most. But most people do not see the underlying HTTP request response process. 200 should be the browser to send the request, the server received the request, set up a successful connection response code. So when the 200 status code, it is normal to send the server file content to the browser side. 304 is when the page refreshes, directly from the cache to get the data. Avoid frequent requests to increase server response pressure, while reducing user waiting to reload CSS, JS. Picture of the time ~



(Accidentally found an egg ~ ~ ~ Baidu Console has recruitment information ~ ~ ~ ~ ~ ~ ~ ~ ~)


At the same time found that I landed status request www.baidu.com with the direct request IP address is not the same protocol, remember the password login under the circumstances is HTTPS protocol, go to 443 ports. The direct IP address is the default 80 port.



Remember the password, will request the landing page, will take the POST request ~

Here will be the HTTP protocol, request the way get and post, the difference is usually a GET request after the URL resource. "With the corresponding parameters, multiple parameters are connected with the ' & '" So if the request is made in Get mode, the request content is usually directly captured in the URL address bar. But get request, will encapsulate the request parameter content in the HTTP request body ~ Seemingly this will be safe, in fact, with Wireshark or fidder grab tool, it can easily capture the HTTP request, the body of the contents of the transmission.


In the past for the interview: Get and post the difference, will often say two points, first, get request way, unsafe. Post security. Second, the content of the GET request parameter has a limited size and the POST request is not restricted.

This is a plausible answer, but the HTTP protocol definition has absolutely nothing to do with it. First, get requests are unsafe, and post requests are also unsafe. The reason is based on grasping a look at the package, the content. Second, the HTTP protocol never restricts the size of the GET request content, but instead browses to the limit of the length of the URL address, and the size of the parameter content requested by different browsers is limited.

This HTTP protocol definition is a bit related, put/delete/get/pos in turn can correspond to the database of the increase, delete, change, check. So get requests are typically data--and content is the same no matter how much the request is, it's not going to change. Of course, get can also take parameters, here in the narrow sense, as long as it will not affect the data structure of the request, are idempotent requests. A GET request is also a standard use in the HTTP protocol definition.

Post, put, delete nature is unequal power requests, will generally change the data structure. Corresponds to changes in the data structure that will occur. If you use the Laravel framework, where the definition of the resource route, you will have a deep understanding of the GET, post, delete, and put request methods.

The same URL address, the same parameter form, because of the request method of Get, post, put, delete different, will occur different behavior. Get a different result.

PHP is a weak language, so I chose the reason for getting started with PHP. It's because PHP is easy to use and not as strict as any other language. Where the GET, POST request should be the most used in PHP, Phper know that you can obtain the GET, post mode of data submitted by $_get/$_post respectively. But often for convenience, we use the $_request global variable to get the value that the foreground has submitted, whether it is a post or a getting method. But this creates a problem, without a strict distinction between get or POST request data. Easy to create a problem, give a simple example: if you delete a piece of data on the page, there is no strict distinction between the submission method, "xxx.delete.php." Id=44 "Similar to this request, can be a phenomenon of this request in a page by default are GET request way, Google Browser has an accelerator, is the GET request in advance of the way things, such as CSS and JS, such as in advance to load in order to speed up the running efficiency. If the page has such a delete request, the data will be deleted unconsciously. This can lead to very serious bug~~. Of course, this is just a simple example of practical understanding, the actual situation is far from easy. However, it is possible to draw a clear picture of how get and post requests, as well as put and delete requests, are still necessary in the project.



On the basis of understanding the HTTP protocol, look at the HTTP request header, body, HTTP answer head ~ Look at this will naturally notice the importance of the message of the danger of clear text transmission. Then deepen the understanding of GET, post, delete and put request mode, especially the routing style of Laravel framework resource strictly follow the restful style.



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.