Skip to content

Instantly share code, notes, and snippets.

@stopthatastronaut
Created May 28, 2017 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stopthatastronaut/7d6a20ee0418bfcfd485177c78f18171 to your computer and use it in GitHub Desktop.
Save stopthatastronaut/7d6a20ee0418bfcfd485177c78f18171 to your computer and use it in GitHub Desktop.
Invoke-UTF8WebRequest
# gets past a problem in Invoke-WebRequest which causes issues with UTF-8 Responses (such as those from raw.githubusercontent.com)
Function Invoke-UTF8WebRequest
{
# based loosely on https://gist.github.com/angel-vladov/9482676
param($uri)
[Net.HttpWebRequest]$req = [Net.WebRequest]::Create($Uri)
[Net.HttpWebResponse]$res = $req.GetResponse()
$sr = [IO.StreamReader]::new($res.GetResponseStream())
$body = $sr.ReadToEnd()
$sr.Close()
return [pscustomobject]@{
Content = $body;
StatusCode = $res.StatusCode;
Headers = $res.Headers;
StatusDescription = $res.StatusDescription;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment