Created
May 28, 2017 03:01
-
-
Save stopthatastronaut/7d6a20ee0418bfcfd485177c78f18171 to your computer and use it in GitHub Desktop.
Invoke-UTF8WebRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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