code: public static String encodeURL(String uri)
    {
      CharBuffer cb = CharBuffer.allocate();
  
      for (int i = 0; i < uri.length(); i++) {
        char ch = uri.charAt(i);
  
        switch (ch) {
        case '<':
        case '>':
        case ' ':
        case '%':
        case '\'':
        case '\"':
          cb.append('%');
          cb.append(encodeHex(ch >> 4));
          cb.append(encodeHex(ch));
          break;
  
        default:
          cb.append(ch);
        }
      }
  
      return cb.close();
    }
docs: Encode the url with '%' encoding.