开发者

Invalid characters for http URL

Can anyone tell me what are the invalid characters for HTTP URL and the best way to validate the same in Java. What I am looking for is URLString validation in t开发者_C百科he URL format: http(s)://ip:port/URLString

Thanks in advance.


You can use any unicode characters you want, as long as they are % encoded. The explicitly reserved characters are defined in section 2.2 of RFC3986: https://www.rfc-editor.org/rfc/rfc3986#section-2

From the document:

  reserved    = gen-delims / sub-delims

  gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"

  sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
              / "*" / "+" / "," / ";" / "="


According to RFC 1738 the following are deemed unsafe:

  1. < and > - delimiters around URLs in free text
  2. " (double quote) - delimits URLs in some systems
  3. - delimits a URL from a fragment/anchor identifier that might follow it

  4. % - used to indicate character encodings

General unsafe characters: { } | \ ^ ~ [ ] `

Edit:

Not a duplicate, but includes some thoughts on validation in Java: Validate URL in java


Read RFC1738 Page 2 and Page 3 on the link for details.


How about using UrlValidator ? isValidPath method probably useful. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜