Skip to content

Instantly share code, notes, and snippets.

@hclpandv
Created November 19, 2018 06:40
Show Gist options
  • Select an option

  • Save hclpandv/53f73258b719ed4173c620d7bb5cc729 to your computer and use it in GitHub Desktop.

Select an option

Save hclpandv/53f73258b719ed4173c620d7bb5cc729 to your computer and use it in GitHub Desktop.
function Invoke-RestApiCall(){
#This is function to be used in PS 2.0 version
param(
[string]$Uri ,
[string]$Method = "GET" ,
[int]$RequestTimeout=60000 , #Milliseconds
[string]$ContentType
)
[Net.HttpWebRequest] $request = [Net.WebRequest]::create($Uri)
$request.Method = "GET"
$request.Timeout = $RequestTimeout
$request.ContentType = $ContentType
$response = $request.getresponse()
[IO.Stream] $Stream = $response.GetResponseStream()
[IO.StreamReader] $Reader = New-Object IO.StreamReader($Stream)
write-output $Reader.readToEnd()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment