views:

37

answers:

1

How can I call a rest based API from a PowerShell script and process the Json answer?

+2  A: 

I created this Get-Http function to make HTTP requests

param([string]$url)

$req = [System.Net.WebRequest]::Create($url)
$req.Method ="GET"
$req.ContentLength = 0

$resp = $req.GetResponse()
$reader = new-object System.IO.StreamReader($resp.GetResponseStream())
$reader.ReadToEnd()

Dealing with the end result as xml is really easy, however, if you want to process JSON you probably will need some .Net library like JSON.Net.

Darrel Miller