When a [[web page]] is requested via the [[HyperText Transfer Protocol]], the server locates a file in its [[file system]] based on the requested [[URL]]. This file may be a regular file or a program. In the second case, the server may (depending on its configuration) run the program, sending its output as the required page. The query string is a part of the URL which is passed to the program. This way, the URL can encode some data that is accessible to the program generating the web page.
==Structure==
The URLs of documents to be generated by programs may contain a query string that is passed to the program. A typical such URL is as follows:
:<code><nowiki>http://server/path/program?query_string</nowiki></code>
When a server receives a request for such a page, it runs the program (if configured to do so) passing the <code>query_string</code> unchanged to the program in some way. The question mark is used as a separator and is not part of the query string. The query string is passed as is to the program.
A link in a Web page may have a URL that contains a query string. However, query strings have been introduced to the aim of passing the content of a [[Web form]] to a program. In particular, when a form containing the fields <code>field<sub>1</sub></code>, <code>field<sub>2</sub></code>, <code>field<sub>3</sub></code> is submitted, the content of the fields are encoded as a query string as follows:
:<code>field<sub>1</sub>=value<sub>1</sub>&field<sub>2</sub>=value<sub>2</sub>&field<sub>3</sub>=value<sub>3</sub>...</code>
* The query string is composed of a series of field=value pairs
* The field-value pairs are each separated by an [[equal sign]]
* The series of pairs is separated by the [[ampersand]], '&' (also by ';' in the newer [[W3C]] recommendations [http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2])</div>
For each [[Field (computer science)|field]] of the form, the query string contains a pair field=value. Web forms may include fields that are not visible to the user, and these fields are included in the query string when the form is submitted.
Technically, the form content is 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 request.
==URL Encoding==
|