Skip to content

Instantly share code, notes, and snippets.

@nolim1t
Created January 7, 2010 05:29
Show Gist options
  • Save nolim1t/271018 to your computer and use it in GitHub Desktop.
Save nolim1t/271018 to your computer and use it in GitHub Desktop.
Sample HTTP Request in Powershell
Powershell HTTP Request
$r = [System.Net.WebRequest]::Create("http://url/")
$resp = $r.GetResponse()
$reqstream = $resp.GetResponseStream()
$sr = new-object System.IO.StreamReader $reqstream
$result = $sr.ReadToEnd()
write-host $result
Username and passwords
$creds = new-object System.Net.NetworkCredential "username", "password"
$uri = mew-object System.Uri "http://url/"
$credcache = new-object System.Net.CredentialCache
$credcache.Add($uri, "Basic", $creds)
$webrequestobject.Credentials = $credcache
@nilesh-akhade
Copy link

Shouldnt we close or dispose the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment