Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid characters for http URL

Tags:

java

http

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 the URL format: http(s)://ip:port/URLString

Thanks in advance.

like image 837
Newbie Avatar asked Jun 24 '11 05:06

Newbie


People also ask

What is an invalid URL format?

A URL in your data feed is badly formed or contains invalid characters. There are several common reasons why you might receive this error: Your URLs contain spaces or symbols.

What characters are invalid in a URL?

These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.

What characters are allowed in a URL?

Thus, only alphanumerics, the special characters " $-_. +! *'(), ", and reserved characters used for their reserved purposes may be used unencoded within a URL.

Is * a valid URL character?

There are only certain characters that are allowed in the URL string, alphabetic characters, numerals, and a few characters ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) # that can have special meanings.


1 Answers

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  = "!" / "$" / "&" / "'" / "(" / ")"
              / "*" / "+" / "," / ";" / "="
like image 138
Mikola Avatar answered Oct 25 '22 01:10

Mikola