-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(maint) Add new query string builder function
- Loading branch information
1 parent
215193d
commit f6d41a7
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function New-HttpQueryString | ||
{ | ||
#Shamelessly taken from https://powershellmagazine.com/2019/06/14/pstip-a-better-way-to-generate-http-query-strings-in-powershell/ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[String] | ||
$Uri, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[Hashtable] | ||
$QueryParameter | ||
) | ||
# Add System.Web | ||
Add-Type -AssemblyName System.Web | ||
|
||
# Create a http name value collection from an empty string | ||
$nvCollection = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) | ||
|
||
foreach ($key in $QueryParameter.Keys) | ||
{ | ||
$nvCollection.Add($key, $QueryParameter.$key) | ||
} | ||
|
||
# Build the uri | ||
$uriRequest = [System.UriBuilder]$uri | ||
$uriRequest.Query = $nvCollection.ToString() | ||
|
||
return $uriRequest.Uri.OriginalString | ||
} |