表单的get和post使用情景
GET和POST兩種方法都是將數(shù)據(jù)送到服務(wù)器,但你該用哪一種呢?
HTTP標(biāo)準(zhǔn)包含這兩種方法是為了達(dá)到不同的目的。POST用于創(chuàng)建資源,資源的內(nèi)容會被編入HTTP請示的內(nèi)容中。例如,處理訂貨表單、在數(shù)據(jù)庫中加入新數(shù)據(jù)行等。
當(dāng)請求無副作用時(如進(jìn)行搜索),便可使用GET方法;當(dāng)請求有副作用時(如添加數(shù)據(jù)行),則用POST方法。一個比較實(shí)際的問題是:GET方法可能會產(chǎn)生很長的URL,或許會超過某些瀏覽器與服務(wù)器對URL長度的限制。
若符合下列任一情況,則用POST方法:
* 請求的結(jié)果有持續(xù)性的副作用,例如,數(shù)據(jù)庫內(nèi)添加新的數(shù)據(jù)行。
* 若使用GET方法,則表單上收集的數(shù)據(jù)可能讓URL過長。
* 要傳送的數(shù)據(jù)不是采用7位的ASCII編碼。
若符合下列任一情況,則用GET方法:
* 請求是為了查找資源,HTML表單數(shù)據(jù)僅用來幫助搜索。
* 請求結(jié)果無持續(xù)性的副作用。
* 收集的數(shù)據(jù)及HTML表單內(nèi)的輸入字段名稱的總長不超過1024個字符。
以上內(nèi)容摘自《Web Database Application with PHP and MySQL, 2nd Edition》一書,中文版《PHP & MySQL Web數(shù)據(jù)庫應(yīng)用開發(fā)指南》。英文原文內(nèi)容如下:
GET versus POST
Both the GET and POST methods send data to the server, but which method should you use?
The HTTP standard includes the two methods to achieve different goals. The POST method was intended to create a resource. The contents of the resource would be encoded into the body of the HTTP request. For example, an order form might be processed and a new row in a database created.
The GET method is used when a request has no side effects (such as performing a search) and the POST method is used when a request has side effects (such as adding a new row to a database). A more practical issue is that the GET method may result in long URLs, and may even exceed some browser and server limits on URL length.
Use the POST method if any of the following are true:
* The result of the request has persistent side effects such as adding a new database row.
* The data collected on the form is likely to result in a long URL if you used the GET method.
* The data to be sent is in any encoding other than seven-bit ASCII.
Use the GET method if all the following are true:
* The request is to find a resource, and HTML form data is used to help that search.
* The result of the request has no persistent side effects.
* The data collected and the input field names in a HTML form are in total less than 1,024 characters in size.
轉(zhuǎn)載于:https://www.cnblogs.com/JsonShare/p/3726969.html
總結(jié)
以上是生活随笔為你收集整理的表单的get和post使用情景的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么申请提工商银行信用卡临时额度?提额条
- 下一篇: LeetCode OJ - Candy