rawurlencode在Android中等效

时间:2015-09-22 05:45:08

标签: php android urlencode url-encoding

我的PHP代码字符串中的rawurlencode($string)函数返回一个字符串。从android编码时我需要相同的字符串。 我使用了以下代码:

encoded_url = URLEncoder.encode(string,"UTF-8");

android和php的结果几乎相同,但android的结果最后附加了%0A。我搜索了它,发现%0A是换行符。我如何删除这个或者是否有更好的等效rawurlencode()?

1 个答案:

答案 0 :(得分:1)

使用encodeUri

 public static String encodeUri(String uri,
                                   String encoding)
                            throws UnsupportedEncodingException
    Encodes the given source URI into an encoded String. All various URI components are encoded according to their respective valid character sets.
    Parameters:
    uri - the URI to be encoded
    encoding - the character encoding to encode to
    Returns:
    the encoded URI
    Throws:
    IllegalArgumentException - when the given uri parameter is not a valid URI
    UnsupportedEncodingException - when the given encoding parameter is not supported