code: public static String urlEncode(String toEncode) {
          String encoded;
          try {
              encoded = URLEncoder.encode(toEncode, ENCODING);
          } catch (UnsupportedEncodingException e) {
              throw new RuntimeException(e);
          }
          // URLEncoder encodes spaces as '+', convert to hex encoding
          encoded = encoded.replaceAll("[+]", "%20");
  
          // Forwad slashes need not be encoded
          encoded = encoded.replaceAll("%2F", "/");
  
          return encoded;
      }
docs: Encodes characters within a string to allow them to be used within a URL.
  Note that the entire URL should not be passed to this method as it will
  encode characters like ':' and '/'.
  
  @param toEncode String to encode
  @return encoded string