Online URL Encoder Tool with References in Java, Python, and Javascript

The world’s simplest URL encoder tool is here. Just type or paste a string in the first textarea. The tool will automatically URL encode your string. You can just click in the second textarea to copy the encoded output.

URL Encoder

URL Encoding a String in Javascript

You can use the encodeURIComponent() function in Javascript to encode a URI string.

var uri = "Hellö Wörld@Javascript"
var encodedURI = encodeURIComponent(uri);
console.log(encodedURI);

// Hell%C3%B6%20W%C3%B6rld%40Javascript

URL Encoding a Query string or Form parameter in Java

Java provides a URLEncoder class for encoding a string into URL encoded format -

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.io.UnsupportedEncodingException;

class URLEncodingExample {

    private static String encodeValue(String value) {
        try {
            return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex.getCause());
        }
    }

    public static void main(String[] args) {
        String value = "Hellö Wörld@Java";
        String encodedValue = encodeValue(value);
        System.out.println(encodedValue);
    }
}
# Output
Hell%C3%B6+W%C3%B6rld%40Java

Note that Java’s URLEncoder class encodes space character " " into a + sign. This is contrary to Javascript which encodes space character into %20.

Check out this StackOverflow discussion to learn what it means to encode the space character into %20 or + sign.

URL Encoding a query string in Python (3+)

Python’s urllib.parse package contains functions to encode a query string -

import urllib.parse

query = "Hellö Wörld@Python"
encodedValue = urllib.parse.quote(query)
print(encodedValue)
# Output
Hell%C3%B6%20W%C3%B6rld%40Python

The quote() function encodes space characters into %20. The urllib.parse package also has a quote_plus function that encodes space characters into + sign -

import urllib.parse

query = "Hellö Wörld@Python"
encodedValue = urllib.parse.quote_plus(query)
print(encodedValue)
#Output
Hell%C3%B6+W%C3%B6rld%40Python

References