Skip to content

Instantly share code, notes, and snippets.

@breezhang
Forked from nickfloyd/gist:1046526
Created August 30, 2012 07:14
Show Gist options
  • Save breezhang/3523645 to your computer and use it in GitHub Desktop.
Save breezhang/3523645 to your computer and use it in GitHub Desktop.
Powershell basic authentication
//This returns a 404 not found - powershell; I expected a 401 if my creds were bad
$Url = "https://github.com/api/v2/xml/commits/list/fellowshiptech/portal/Portal_2011.6.23_15-26"
$webclient = new-object system.net.webclient
$webclient.credentials = new-object system.net.networkcredential("user", "password")
$result = $webclient.DownloadString($Url)
$result
//This returns the data I want via terminal
curl -u user:password https://github.com/api/v2/xml/commits/list/fellowshiptech/portal/Portal_2011.6.23_15-26
//Here's how to do it via powershell - though I am not a fan of the implementation
$webclient = new-object system.net.webclient
$result = $webclient.DownloadString("https://github.com/api/v2/xml/commits/list/fellowshiptech/portal/Portal_2011.6.23_15-26?login=:user&token=:token")
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment