更新时间:2023-02-18 16:55:05
(以下是***条目链接部分的文本.)
(Following is the text of the linked section of the Wikipedia entry.)
包含查询字符串的典型 URL 如下:
A typical URL containing a query string is as follows:
http://server/path/program?query_string
当服务器收到对此类页面的请求时,它会运行一个程序(如果配置为这样做),将未更改的 query_string 传递给该程序.问号用作分隔符,不是查询字符串的一部分.
When a server receives a request for such a page, it runs a program (if configured to do so), passing the query_string unchanged to the program. The question mark is used as a separator and is not part of the query string.
网页中的链接可能有一个包含查询字符串的 URL,但是,HTML 定义了 Web 浏览器生成查询字符串的三种方式:
A link in a web page may have a URL that contains a query string, however, HTML defines three ways a web browser can generate the query string:
查询字符串的主要用途是包含 HTML 表单(也称为 Web 表单)的内容.特别是,当提交包含字段 field1、field2、field3 的表单时,字段的内容被编码为查询字符串,如下所示:
The main use of query strings is to contain the content of an HTML form, also known as web form. In particular, when a form containing the fields field1, field2, field3 is submitted, the content of the fields is encoded as a query string as follows:
field1=value1&field2=value2&field3=value3...
field1=value1&field1=value2&field1=value3...
对于表单的每个字段,查询字符串包含一对字段=值.Web 表单可能包含用户不可见的字段;提交表单时,这些字段包含在查询字符串中
For each field of the form, the query string contains a pair field=value. Web forms may include fields that are not visible to the user; these fields are included in the query string when the form is submitted
该约定是 W3C 推荐的.W3C 建议所有 Web 服务器都支持除与符号分隔符之外的分号分隔符 [6],以允许在 HTML 文档中的 URL 中使用 application/x-www-form-urlencoded 查询字符串,而无需实体转义与符号.
This convention is a W3C recommendation. W3C recommends that all web servers support semicolon separators in addition to ampersand separators[6] to allow application/x-www-form-urlencoded query strings in URLs within HTML documents without having to entity escape ampersands.
从技术上讲,表单内容仅在表单提交方法为 GET 时编码为查询字符串.提交方式为POST时默认使用相同的编码,但结果不作为查询字符串发送,即不添加到表单的action URL中.相反,该字符串作为 HTTP 请求的正文发送.
Technically, the form content is only encoded as a query string when the form submission method is GET. The same encoding is used by default when the submission method is POST, but the result is not sent as a query string, that is, is not added to the action URL of the form. Rather, the string is sent as the body of the HTTP request.