Parameter separator in URLs, the case of misused question mark

前端 未结 3 1979
無奈伤痛
無奈伤痛 2021-01-11 09:27

What I don\'t really understand is the benefit of using \'?\' instead of \'&\' in urls:

\"question

相关标签:
3条回答
  • 2021-01-11 10:08

    From the URI spec's (RFC 3986) point of view, the only separator here is "?". the format of the query is opaque; the ampersands just are something that HTML happens to use for form submissions.

    0 讨论(0)
  • 2021-01-11 10:15

    The answer's pretty much in this article - http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/ . To highlight it, here goes :

    Query is the preferred way to send some parameters to a resource on the server. These are key=value pairs and are separated from the rest of the URL by a ? (question mark) character and are normally separated from each other by & (ampersand) characters. What you may not know is the fact that it is legal to separate them from each other by the ; (semi-colon) character as well. The following URLs are equivalent:

    http://www.blah.com/some/crazy/path.html?param1=foo&param2=bar

    http://www.blah.com/some/crazy/path.html?param1=foo;param2

    0 讨论(0)
  • 2021-01-11 10:19

    The RFC 3896 (https://www.ietf.org/rfc/rfc3986.txt) defines general and sub delimiters ... '?' is a general, '&' and ';' are sub. The spec is pretty clear about that.

    In this case the latter '?' chars would be treated as part of the query. If the query parser follows the spec strictly, it would then pass the whole query on to the app-destination. If the app-destination could choose to further process the query string in a manner which treats the ? as a param name-value pairs delimiter, that is up to the app's designers.

    My guess is that this often 'just works' because code that splits query strings and the original uri uses all delimiters for matching: 1) first query is split on '?' then 2) query string is parsed using char match list that includes '?' (convenience only).... This could be occurring in ubiquitous parsing libraries already.

    0 讨论(0)
提交回复
热议问题