如何转义非法字符'|'

How to escape Illegal Character '|'

Url 我用来解析使用 Json 读取的文档的是:

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

这是投掷 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

当我尝试使用 urlEncoder.encode() 对 url 进行编码时,它导致了另一个异常:

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

when I am trying to encode the url

不要 URL 对整个 URL 进行编码。只需对部分进行编码,例如 access_token 的值部分。那应该把 | 变成 %7c.