Recently I was doing some work related to file uploading, etc., and encountered the following problems during the process:
Submit the form to a url with parameters (such as: res.php?param=aaa) in post mode, what will be the result?
The following will test the content related to get and post from several examples. First, let’s look at the simplest one
<html> <body> <?php echo $_GET ['param']; ?> <form action="get_post_test.php?param=aaa" method="get"> <input type="text" name="param" value="bbb" /> <input type="submit" value="submit"> </form> </body> </html>
Submit to the url that already has this parameter in the get method. The result is that the corresponding value is overwritten, and the obtained param is bbb.
What if the parameters in the url are different from the name in the form? See the test example below
<html> <body> <?php echo $_GET ['param1']; echo "<br>"; echo $_GET ['param2']; ?> <form action="get_post_test.php?param1=aaa" method="get"> <input type="text" name="param2" value="bbb" /> <input type="submit" value="submit"> </form> </body> </html>
The result of this is that the value of param2 is correctly obtained, but the value of param1 is not obtained, indicating that submitting in the get method removes the parameters of the original url.
Let’s take a look at the submission via post
First, let’s look at the situation when the name values are the same
<html> <body> <?php echo "get=" . $_GET ['param']; echo "<br>"; echo "post=" . $_POST ['param']; ?> <form action="get_post_test.php?param=aaa" method="post"> <input type="text" name="param" value="bbb" /> <input type="submit" value="submit"> </form> </body> </html>
In this case, the output result is aaa obtained by the get method, and bbb obtained by the post method, indicating that there is no influence on each other in this case. Get and post are isolated separately.
Let’s take a look at how to use the post method to obtain the parameters behind the url
<html> <body> <?php echo "get=" . $_GET ['param2']; echo "<br>"; echo "post=" . $_POST ['param1']; ?> <form action="get_post_test.php?param1=aaa" method="post"> <input type="text" name="param2" value="bbb" /> <input type="submit" value="submit"> </form> </body> </html>
In this case, all the parameters obtained are empty, so it can be said that the parameters obtained by get and post in PHP are isolated from each other.
However, when using Java to upload files today, all the data can be obtained correctly, that is, you can use request in the servlet to obtain the form data of the post or the get data after the URL. After all, the method of obtaining parameters in the servlet is the same.
You can directly see the submitted parameters in the get address bar, and the size is limited. Different browsers have different byte limits.
Post does not limit the size. You can't see it in the address bar.
You can query it. Use get
and try to use post
for other operations.
Select C
1. Difference: In Form, you can use post or get. They are all legal values of method. However, there are at least the following differences in the use of the post and get methods: 1. The Get method passes user input through URL requests. The parameters and values passed by the Get method are displayed in the URL in the form of ?name=value&name=value. The Post method takes another form. 2. Submitting data through the get method may cause security issues. For example, a landing page. When submitting data via the get method, the username and password will appear on the URL. If the login page can be cached by the browser or others can access the customer's machine. Then, others can read the customer's account number and password from the browser's history. Therefore, in some cases, the get method can cause serious security problems. 3. Obviously the limitation of the Get method is that it is inconvenient when there are many values to be transferred, otherwise the URL may be too long and cause an error. I think it is safer to use post if it is not necessary