Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html" rel="noreferrer"><code>URLEncoder</code></a> should be the way to go. You only need to keep in mind to encode <em>only</em> the individual query string parameter name and/or value, not the entire URL, for sure not the query string parameter separator character <code>&amp;</code> nor the parameter name-value separator character <code>=</code>.</p> <pre><code>String q = "random word £500 bank $"; String url = "http://example.com/query?q=" + URLEncoder.encode(q, "UTF-8"); </code></pre> <hr> <p>Note that spaces in query parameters are represented by <code>+</code>, not <code>%20</code>, which is legitimately valid. The <code>%20</code> is usually to be used to represent spaces in URI itself (the part before the URI-query string separator character <code>?</code>), not in query string (the part after <code>?</code>).</p> <p>Also note that there are two <code>encode()</code> methods. One without charset argument and another with. The one without charset argument is deprecated. Never use it and always specify the charset argument. The <a href="http://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html" rel="noreferrer">javadoc</a> even explicitly recommends to use the UTF-8 encoding, as mandated by <a href="http://tools.ietf.org/html/rfc3986" rel="noreferrer">RFC3986</a> and <a href="http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars" rel="noreferrer">W3C</a>.</p> <blockquote> <p>All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte. <strong>The recommended encoding scheme to use is UTF-8</strong>. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.</p> </blockquote> <h3>See also:</h3> <ul> <li><a href="https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/" rel="noreferrer">What every web developer must know about URL encoding</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload