What is a valid URL query string?

后端 未结 3 1853
醉话见心
醉话见心 2020-12-10 13:39

What characters are allowed in an URL query string?

Do query strings have to follow a particular format?

3条回答
  •  感情败类
    2020-12-10 14:21

    Per http://tools.ietf.org/html/rfc3986

    In section 2.2 Reserved Characters, the following characters are listed:

    reserved = gen-delims / sub-delims

    gen-delims = “:” / “/” / “?” / “#” / “[” / “]” / “@”

    sub-delims = “!” / “$” / “&” / “’” / “(” / “)” / “*” / “+” / “,” / “;” / “=”

    The spec then says:

    If data for a URI component would conflict with a reserved character’s purpose as a delimiter, then the conflicting data must be percent-encoded before the URI is formed.

    Next, in section 2.3 Unreserved Characters, the following are listed:

    unreserved = ALPHA / DIGIT / “-” / “.” / “_” / “~”

提交回复
热议问题