URL Encoder Tool - Percent Encoding

Share:

Enter or paste your URL in the first text box and click Encode URL button.

The URL will be encoded and appears in the second box below.

*


About URL Encoding (Percent Encoding)

URL Decoder

URL Encoding is also called as Percent-Encoding. It's because the Unsafe ASCII characters in the URL is encoded to % followed by hexadecimal code.

The browser can recognize the URL in standard ASCII format; especially the URI reserved character set should be used for their intended purpose only. for example the forward slash () is an URI reserved character to delimit the components in the URL. If you want to use a forward slash () to represent some thing else in the URL, then you have to encode it with percent-encoding format.

The above URL encoder tools will help you to encode your URL to percent-encoded format. For example, it converts the URL "http://www.mytecbits.com/tools/url/urlencoder" to "http%3a%2f%2fwww.mytecbits.com%2ftools%2furl%2furlencode".

Below is the list of percent-encoed URI reserved characters including few of the commonly used symbols like space, percent, etc...

URI Reserved and Special Characters Percent-Encoded codes Description
 %20Space (space is also represented as "+" in URL Encoding)
!%21Exclamation mark
#%23Number Sign (Hash tag)
$%24Dollar Sign
%%25Percent
&%26Ampersand
'%27Apostrophe
(%28Opening Bracket
)%29Closing Bracket
*%2AAsterisk (Star)
+%2BPlus Sign
,%2CComma
/%2FForward Slash
:%3AColon
;%3BSemicolon
=%3DEqual Sign
?%3FQuestion Sign
@%40At Sign
[%5BOpening Square Bracket
]%5DClosing Square Bracket
"%22Quotation Mark
-%2DHyphen (Dash)
.%2EFull Stop
<%3CLesser Than Sign
>%3EGreater Than Sign
\%5CBackward Slash
_%5FUnderscore
|%7CSipe (Vertical Bar)

Programming URL Encoding with .Net

.Net provides two options to encode url. You can use either HttpServerUtility.UrlEncode method or the HttpUtil.UrlEncode method in the System.Web namespace. Both these UrlEncode methods give the same result.

Example URL Encoding with C# .Net

using System.Web.Mvc;

namespace SampleCodeSolution.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Contact()
        {
            string sUrl;
            string strQueryStringUrl = "http://www.mytecbits.com/tools/url/urlencoder";
            sUrl = "~/NextPage?url=" + Server.UrlEncode(strQueryStringUrl);
            return View(sUrl);
        }
    }
}

Programming URL Encoding with Java

Java provides URLEncoder class to encode url query string. The URLEncoder class has the method encode which takes in the string to be encoded and returns the percent encoded string.

Example URL Encoding with Java

import java.net.URLEncoder;
public class MTBSampleEncode {
  public static void main(String args[]) {
        try {
	        String urlQueryString = "http://www.mytecbits.com/tools/url/urlencoder";
	        String encodedQueryString = URLEncoder.encode(urlQueryString, "UTF-8");
	        System.out.println("Encoded URL Query String: " + encodedQueryString);
	    } 
        catch (UnsupportedEncodingException e) {
		    System.err.println(e);
	    }
    }
}

Programming URL Encoding with JavaScript

JavaProvides provides two functions encodeURI() and encpdeUTIComponent() to encode the url.

encodeURI() function

The encodeURI() function encodes all the special charactors in an URI except / , @ : = & $ + # ? which takes in the string to be encoded and returns the percent encoded string.

Example URL Encoding with JavaScript's encodeURI()

<script>
    var urlToEncode = "http://www.mytecbits.com/tools/url/urlencoder?Encode this ' text";
    var encodedUrl = encodeURI(urlToEncode);
    alert(encodedUrl);
</script>

The result of above encoding will be http://www.mytecbits.com/tools/url/urlencoder?Encode%20this%20'%20text

encpdeUTIComponent() function.

encpdeUTIComponent() function encodes all the special charactors including the once which are left out by encodeURI().

Example URL Encoding with JavaScript's encpdeUTIComponent()

<script>
    var urlToEncode = "http://www.mytecbits.com/tools/url/urlencoder?Encode this ' text";
    var encodedUrl = encodeURIComponent(urlToEncode);
    alert(encodedUrl);
</script>

The result of above encoding will be http%3A%2F%2Fwww.mytecbits.com%2Ftools%2Furl%2Furlencoder%3FEncode%20this%20'%20text

Reference


Page Last Modified On: Jul 23, 2021


Disclaimer: We took every effort to provide higher level of accuracy in the calculators, converters and tools we have added to www.MyTecBits.com Tools section. But, we cannot give any guarantee or can be held responsible for any errors, defects, faults or mistakes in any of the calculators, converters or tools. Please see detailed terms of use and liability disclaimer in Terms of Use Page.

Follow Us