词条 | Query string |
释义 |
On the internet, a query string is the part of a uniform resource locator (URL) which assigns values to specified parameters. The query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML form. A web server can handle a Hypertext Transfer Protocol request either by reading a file from its file system based on the URL path or by handling the request using logic that is specific to the type of resource. In cases where special logic is invoked, the query string will be available to that logic for use in its processing, along with the path component of the URL. StructureTypical URL containing a query string is as follows: {{bq|1=http://example.com/over/there?name=ferret }}When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, Web frameworks may provide methods for parsing multiple parameters in the query string, separated by some delimiter.[4] In the example URL below, multiple query parameters are separated by the ampersand, " http://example.com/path/to/page?name=ferret&color=purple }}The order of the queries doesn't matter ( A link in a web page may have a URL that contains a query string. HTML defines three ways a user agent can generate the query string:
Web formsOne of the original uses was to contain the content of an HTML form, also known as web form. In particular, when a form containing the fields field1=value1&field2=value2&field3=value3... }}
While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. For each field of the form, the query string contains a pair This convention is a W3C recommendation.[5] 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. The form content is only encoded in the URL's 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 submitted as the HTTP request body rather than being included in a modified URL. Indexed searchBefore forms were added to HTML, browsers rendered the {{tag|isindex|open}} element as a single-line text-input control. The text entered into this control was sent to the server as a query string addition to a GET request for the base URL or another URL specified by the {{code|action}} attribute.[7] This was intended to allow web servers to use the provided text as query criteria so they could return a list of matching pages.[8] When the text input into the indexed search control is submitted, it is encoded as a query string as follows: {{bq|1=argument1+argument2+argument3... }}
Though the {{tag|isindex|open}} element is deprecated and most browsers no longer support or render it, there are still some vestiges of indexed search in existence. For example, this is the source of the special handling of plus sign, ' URL encoding{{Main|Percent-encoding}}Some characters cannot be part of a URL (for example, the space) and some other characters have a special meaning in a URL: for example, the character HTML 5 specifies the following transformation for submitting HTML forms with the "get" method to a web server. The following is a brief summary of the algorithm:
The octet corresponding to the tilde (" The encoding of SPACE as ' ExampleIf a form is embedded in an HTML page as follows: and the user inserts the strings “this is a field” and “was it clear (already)?” in the two text fields and presses the submit button, the program
If the form is processed on the server by a CGI script, the script may typically receive the query string as an environment variable named TrackingA program receiving a query string can ignore part or all of it. If the requested URL corresponds to a file and not to a program, the whole query string is ignored. However, regardless of whether the query string is used or not, the whole URL including it is stored in the server log files. These facts allow query strings to be used to track users in a manner similar to that provided by HTTP cookies. For this to work, every time the user downloads a page, a unique identifier must be chosen and added as a query string to the URLs of all links the page contains. As soon as the user follows one of these links, the corresponding URL is requested to the server. This way, the download of this page is linked with the previous one. For example, when a web page containing the following is requested: a unique string, such as The addition of the query string does not change the way the page is shown to the user. When the user follows, for example, the first link, the browser requests the page This way, any subsequent page request from this user will carry the same query string The main differences between query strings used for tracking and HTTP cookies are that:
Compatibility issuesAccording to the HTTP specification: Various ad hoc limitations on request-line length are found in practice. It is RECOMMENDED that all HTTP senders and recipients support, at a minimum, request-line lengths of 8000 octets.[9] If the URL is too long, the web server fails with the 414 Request-URI Too Long HTTP status code. The common workaround for these problems is to use POST instead of GET and store the parameters in the request body. The length limits on request bodies are typically much higher than those on URL length. For example, the limit on POST size, by default, is 2 MB on IIS 4.0 and 128 KB on IIS 5.0. The limit is configurable on Apache2 using the See also
References1. ^{{cite web| url = http://tools.ietf.org/html/rfc3986#section-3| title = RFC 3986| author = T. Berners-Lee, W3C/MIT, R. Fielding, Day Software, L. Masinter, Adobe Systems| date = January 2005| at = "Syntax Components" (section 3)}} [11]2. ^{{cite web| url = http://tools.ietf.org/html/rfc3986#section-3.4| title = RFC 3986| author = T. Berners-Lee, W3C/MIT, R. Fielding, Day Software, L. Masinter, Adobe Systems| date = January 2005| at = "Query" (section 3.4)}} 3. ^{{cite web|url=http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterValues(java.lang.String) |title=ServletRequest (Java EE 6 )|website=docs.oracle.com |date=2011-02-10|accessdate=2013-09-08}} 4. ^{{cite web|url=https://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys |title=uri – Authoritative position of duplicate HTTP GET query keys|website=Stack Overflow |date=2013-06-09|accessdate=2013-09-08}} 5. ^1 Forms in HTML documents. W3.org. Retrieved on 2013-09-08. 6. ^Performance, Implementation, and Design Notes. W3.org. Retrieved on 2013-09-08. 7. ^{{cite web |title=<isindex> |url=https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex |website=HTML (HyperText Markup Language)}} 8. ^{{cite web |title=HTML/Elements/isindex |url=http://www.w3.org/wiki/HTML/Elements/isindex |website=W3C Wiki}} 9. ^HTTP/1.1 Message Syntax and Routing. ietf.org. Retrieved on 2014-07-31. 10. ^core – Apache HTTP Server. Httpd.apache.org. Retrieved on 2013-09-08. 11. ^1 The [https://www.w3.org/TR/html52/sec-forms.html#application-x-www-form-urlencoded-encoding-algorithm application/x-www-form-urlencoded encoding algorithm], HTML5.2, W3C recommendation, 14 December 2017 }} External links
2 : World Wide Web|URL |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。