Do colons require encoding in URI query parameters?

前端 未结 2 1437
Happy的楠姐
Happy的楠姐 2021-02-04 01:42

I\'ve noticed that Java\'s UriBuilder isn\'t encoding the : characters included in my query parameter values (ISO 8601-formatted strings).

Acco

相关标签:
2条回答
  • 2021-02-04 01:55

    There's no UriBuilder in the Java SDK, it is defined by JAX-RS. It's documentation states query parameters should be URL encoded, other components are encoded using RFC 3986.

    Builder methods perform contextual encoding of characters not permitted in the corresponding URI component following the rules of the application/x-www-form-urlencoded media type for query parameters and RFC 3986 for all other components

    However, the Jersey implementation of JAX-RS doesn't play by this spec, and encodes everything according to RFC 3986. It is a bug, see the JIRA ticket.

    0 讨论(0)
  • 2021-02-04 02:07

    Yes, they should be encoded in a query string. The correct encoding is %3A

    However, I can understand why UriBuilder isn't encoding :. You don't want to encode the colon after the protocol (eg http:) or between the username and password (eg ftp://username:password@domain.com) in an absolute URI.

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