Android 中的等效 rawurlencode

rawurlencode equivalent in Android

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

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

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

使用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