URL 参数和查询字符串有什么区别? [英] What is the difference between URL parameters and query strings?

查看:67
本文介绍了URL 参数和查询字符串有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 URL 中,我没有看到参数和查询字符串之间有太大区别.那么有什么区别,什么时候应该使用一个而不是另一个?

I don't see much of a difference between the parameters and the query strings, in the URL. So what is the difference and when should one be used over the other?

推荐答案

查询组件 由 URI 中的第一个 ? 表示.查询字符串"可能是同义词(URI 标准中未使用该术语).

The query component is indicated by the first ? in a URI. "Query string" might be a synonym (this term is not used in the URI standard).

带有查询组件的 HTTP URI 的一些示例:

Some examples for HTTP URIs with query components:

http://example.com/foo?bar
http://example.com/foo/foo/foo?bar/bar/bar
http://example.com/?bar
http://example.com/?@bar._=???/1:
http://example.com/?bar1=a&bar2=b

(查询组件中允许的字符列表)

查询组件的格式"取决于 URI 作者.一个常见的约定(但仅是一个约定,就 URI 标准而言¹)是使用键值对的查询组件,又名.参数,就像上面最后一个例子:bar1=a&bar2=b.

The "format" of the query component is up to the URI authors. A common convention (but nothing more than a convention, as far as the URI standard is concerned¹) is to use the query component for key-value pairs, aka. parameters, like in the last example above: bar1=a&bar2=b.

此类参数也可能出现在其他 URI 组件中,即路径²和片段.就 URI 标准而言,使用哪个组件和哪种​​格式取决于您.

Such parameters could also appear in the other URI components, i.e., the path² and the fragment. As far as the URI standard is concerned, it’s up to you which component and which format to use.

在路径、查询和片段中包含参数的示例 URI:

Example URI with parameters in the path, the query, and the fragment:

http://example.com/foo;key1=value1?key2=value2#key3=value3

<小时>

¹ URI 标准说关于查询组件:

[…] 查询组件通常以键=值"对的形式携带识别信息[…]

[…] query components are often used to carry identifying information in the form of "key=value" pairs […]

² URI 标准说关于路径组件:

[…] 分号 (";") 和等号 ("=") 保留字符通常用于分隔适用于该段的参数和参数值.逗号 (",") 保留字符通常用于类似目的.

[…] the semicolon (";") and equals ("=") reserved characters are often used to delimit parameters and parameter values applicable to that segment. The comma (",") reserved character is often used for similar purposes.

这篇关于URL 参数和查询字符串有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆