URL Encoder Online

URL Encoder Online


URL Encoder is an online tool for encoding URLs. URL encoding stands for encoding certain characters in a URL by replacing them with one or more character triplets that consist of the percent character "%" followed by two hexadecimal digits. The two hexadecimal digits of the triplet(s) represent the numeric value of the replaced character.
Check out the URL decoder online tool at URL Decoder Online.




URL Encoding Example

URL input:
https://www.javaguides.net/p/url-encoder-online.html
Encoded URL output:
https%3A%2F%2Fwww.javaguides.net%2Fp%2Furl-encoder-online.html

Encode URL in JavaScript

 The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
var uri = "https://javaguides.net/my test.html?name=ram&age29";
console.log("before encode :: " + uri);
var encode = encodeURIComponent(uri); 
console.log("after encode :: " + encode);

var decode = decodeURIComponent(encode);
console.log("after decode :: " + decode);
Output:
before encode :: https://javaguides.net/my test.html?name=ram&age29
after encode :: https%3A%2F%2Fjavaguides.net%2Fmy%20test.html%3Fname%3Dram%26age29
after decode :: https://javaguides.net/my test.html?name=ram&age29
Read more about how to encode and decode URL in JavaScript in a blog post at Encode and Decode URL in JavaScript.

URL Encode in Java

The Java provides built-in URLEncoder class, which is a Utility class for HTML form encoding. This class contains static methods for converting a String to the application/x-www-form-urlencoded MIMEformat.
When encoding a String, the following rules apply:
  • The alphanumeric characters "a" through"z", "A" through"Z" and "0" through "9" remain the same.
  • The special characters ".","-", "*", and"_" remain the same.
  • The space character " " is converted into a plus sign "+".
  • 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. The recommended encoding scheme to use is UTF-8. However, for compatibility reasons, if an encoding is not specified, then the default encoding of the platform is used.

URLEncoder Class Example

The URLEncoder utility class provides a encode() method which translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.
The below program demonstrate the usage of encode() method to encode URL - "https://www.javaguides.net/search?q=core+java+tutorial":
package net.javaguides.network;

import java.io.UnsupportedEncodingException;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

public class URLEncoderExample {

    public static void main(String[] args) throws MalformedURLException, UnsupportedEncodingException {
        // base URL 
        String baseurl = "https://www.javaguides.net/search?q=";

        // String to be encoded 
        String query = "core+java+tutorial";

        System.out.println("URL without encoding :");
        URL url = new URL(baseurl + query);
        System.out.println(url);

        // encode() method 
        System.out.println("URL after encoding :");
        url = new URL(baseurl + URLEncoder.encode(query, "UTF-8"));
        System.out.println(url);
    }
}
Output:
URL without encoding :
https://www.javaguides.net/search?q=core+java+tutorial
URL after encoding :
https://www.javaguides.net/search?q=core%2Bjava%2Btutorial
Check out how to encode and decode URLs in Java at Java URLEncoder and URLDecoder Class Examples

URL Encoding Table

CharacterPercent
Enconding
(space)%20
!%21
"%22
#%23
$%24
%%25
&%26
'%27
(%28
)%29
*%2A
+%2B
,%2C
/%2F
:%3A
;%3B
<%3C
=%3D
>%3E
?%3F
@%40
[%5B
\%5C
]%5D
^%5E
`%60
{%7B
|%7C
}%7D

URL Decoder Online Tool

Check out the URL decoder online tool at URL Decoder Online.

Comments