Here you can find the source of percentEncodeRfc3986(final String string)
Parameter | Description |
---|---|
string | Decoded string. |
public static String percentEncodeRfc3986(final String string)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.*; public class Main { /**/* w w w .j a v a2s. c om*/ * Percent-encode values according the RFC 3986. The built-in Java URLEncoder does not encode * according to the RFC, so we make the extra replacements. * * @param string Decoded string. * @return Encoded string per RFC 3986. */ public static String percentEncodeRfc3986(final String string) { try { return URLEncoder.encode(string, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); } catch (final UnsupportedEncodingException e) { return string; } } }