首页 文章

rawurlencode在Android中等效

提问于
浏览
1

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

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

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

1 回答

  • 0

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

相关问题