0

I'm using Jsoup to connect to a URL with a space in it but keep getting a URI syntax error. Any ideas on how deal with this?

Thanks!!

user1152327
  • 149
  • 12

2 Answers2

0

URLs cannot have spaces, by RFC1738 (section 2.2): http://www.ietf.org/rfc/rfc1738.txt

For some additional background on how to handle this, see: http://www.w3schools.com/tags/ref_urlencode.asp

In particular, one mechanism for encoding URLs can be found at: HTTP URL Address Encoding in Java

Community
  • 1
  • 1
jeffrey_t_b
  • 1,779
  • 12
  • 18
0

You should percent-encode URLs. Space is represented as %20.

Additionally, some characters/symbols are used as delimiters in URLs (&, ?, =, etc.) and thus they cannot be put in the URL unless they are meant as delimiters. For example, if you wanted to pass the string "1 &1" I would have to encode it as "1%20%261" or else it will not parse properly.

See http://en.wikipedia.org/wiki/Percent-encoding for more details.

Kevin
  • 1,666
  • 9
  • 10