當(dāng)用戶在 HTML 表單 (HTML Form) 中輸入信息并提交之后,有兩種方法將信息從瀏覽器傳送到 Web 服務(wù)器 (WebServer)。
一種方法是通過 URL,另外一種是在 HTTP Request 的 body 中。
前一種方法,我們使用 HTML Form 中的 method = "get",后一種方法我們使用HTML Form 中的 method ="post"。
例句如下:
<form action = "..." method = "get">
<from action = "..." method = "post">
通過 get 或者 post 方法都可以獲得 Form 的數(shù)據(jù),兩者主要區(qū)別在于以下幾方面:
Get
Post
我們看看 get 是如何提交 Form 數(shù)據(jù)的。我們先寫一個 HTML 文件,如下:
<html>
<head><title>Blablar.com HTML Form Method Get Example</title></head>
<body>
<form action ="get.php" method ="get">
Name: <input type="text" name="username" />
<input type ="submit" value="ok" />
</form>
</body>
</html>
你可以看到在瀏覽器地址欄里的URL是:
http://localhost:8080/get.php?username=Jacky
注意get.php后面的字符串 ?username=Jacky,這是一對name/value 數(shù)據(jù),前面加一個問號。
如果你將 form 改成 method = "post",你在瀏覽器地址欄就看不到這對name/value 數(shù)據(jù),而只有:
http://localhost:8080/get.php
使用 get 時,第一對 name/value 值前要加一個問號? ,以后每對name/value 值則要用 & 分開。比如一個form中有三個參數(shù),如下:
<form action ="u.php" method ="get">
Name: <input type="text" name="username" />
Age: <input type="text" name="age" />
Gender: <input type="text" name="gender" />
<input type ="submit" value="ok" />
</form>
比如你在Name 項填寫Jacky,Age項填寫50,Gender項填了male,提交之后的 URL 顯示為:
http://localhost:8080/get.php?username=Jacky&age=50&gender=male
愛華網(wǎng)



