Last active
January 27, 2018 07:59
-
-
Save VimalShekar/0daedbaae98447ef45d22877329ac744 to your computer and use it in GitHub Desktop.
Helper functions to help in URL encoding and Decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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