Search code examples
androidjsonurlillegalargumentexceptionillegal-characters

How to escape Illegal Character '|'


Url which I am using to parse a document read using Json is:

https://graph.facebook.com/150205375156742/feed?access_token=520625188052604|GsCYVGBJKs5N_O1AX9XrrsulrWc

which is throwing IllegalArgumentException:

04-19 23:08:02.220: E/AndroidRuntime(17068): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 76: https://graph.facebook.com/150205375156742/feed?access_token=520625188052604|GsCYVGBJKs5N_O1AX9XrrsulrWc

when I am trying to encode the url using urlEncoder.encode() it is causing another exception:

04-20 11:43:16.280: W/System.err(31984): java.net.UnknownHostException: Unable to resolve host "graph.facebook.com": No address associated with hostname

Solution

  • when I am trying to encode the url

    Don't URL encode the whole URL. Just encode the parts, for example the value part of access_token. That should turn the | to %7c.