Skip to content

Instantly share code, notes, and snippets.

@VimalShekar
Last active January 27, 2018 07:59
Show Gist options
  • Save VimalShekar/0daedbaae98447ef45d22877329ac744 to your computer and use it in GitHub Desktop.
Save VimalShekar/0daedbaae98447ef45d22877329ac744 to your computer and use it in GitHub Desktop.
Helper functions to help in URL encoding and Decoding
#
# Typically the standard practice during HTTP communication requires you to encode, certain characters that are not allowed
# in the URI naming convention. System.Web.HttpUtility class has methods to help you conver these characters to the encoded
# format. Here's a helper function in powershell.
#
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
function EncodeUrl( [string] $URL )
{
$Encode = [System.Web.HttpUtility]::UrlEncode($URL)
return $Encode
}
function DecodeEncodedUrl( [string] $EncURL )
{
$Decode = [System.Web.HttpUtility]::UrlDecode($EncURL)
return $Decode
}
# Example Usage:
# $res = EncodeUrl "https://blogs.technet.microsoft.com/askcore/tag/vimal-shekar/"
# DecodeEncodedUrl $res
#
# Example
# Encoded URL - Http%3a%2f%2fwww.hotmail.com for http://www.hotmail.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment